Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » How to use variables in Page controls?

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

Page: 1
Go to End
Author Topic: 1442 Views
  • lise
    Avatar
    Community Member
    47 Posts

    How to use variables in Page controls? Link to this post

    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

  • AlknicTeos
    Avatar
    Community Member
    5 Posts

    Re: How to use variables in Page controls? Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: How to use variables in Page controls? Link to this post

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

    1442 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.