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?


3 Posts   1507 Views


21 January 2010 at 4:31pm Community Member, 47 Posts

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.


21 January 2010 at 9:55pm (Last edited: 21 January 2010 9:59pm), Community Member, 5 Posts

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....


22 January 2010 at 4:32pm Forum Moderator, 5511 Posts

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 %>