Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

How to use variables in Page controls?


Reply


3 Posts   1575 Views

Avatar
lise

Community Member, 47 Posts

21 January 2010 at 4:31pm

I am sure this question is trivial but I can't find an answer (and I can't make it work either!) .

I would like to use a variable ($ProductUrl) to access the corresponding page with <% control page ($ProductUrl) %>

My code looks like this :

<% control AGProductInfo %>
<h2> $ProductUrl </h2>
<% control page($ProductUrl) %>
<div> $ProductIntro</div>
<% end_control %>
<% end_control %>

AGProductInfo is a DataObject containing the URL to a Product Page.

static $db = array(
'ProductUrl' => 'Text'
   );

$ProductUrl is the URLSegment and is printed correctly in the <h2> line and, yes, the page exists.
However <% control page($ProductUrl) %> does not work ( I get a blank/empty page ).

I am obviously doing something wrong here. Is it possible to pass a variable to a page control? If not, what is the correct way
to directly access a page in a template ?

Any help would be highly appreciated.
Thanks

Avatar
AlknicTeos

Community Member, 5 Posts

21 January 2010 at 9:55pm

Edited: 21/01/2010 9:59pm

Well, its not completly clear what you want.

If you want something like a overview with the Url and beneath ProductIntro (description text?) .
Well, when the AGProductInfo has a ProductUrl and a ProductIntro

<% control AGProductInfo %>
<h2> $ProductUrl </h2>
<div> $ProductIntro</div>
<% end_control %>

should function.

..hope wrote no nonsense....

Avatar
Willr

Forum Moderator, 5513 Posts

22 January 2010 at 4:32pm

lise - in your orignal post code like <% control page($ProductUrl) %> will not work in the templates. You cannot pass dynamic variables into functions. You would have to create something like a RelatedPage function on the AGProductInfo object then use <% control RelatedProducts %>