Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Control Loop not being interpreted properly by template builder

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

Page: 1
Go to End
Author Topic: 781 Views
  • azt3k
    Avatar
    Community Member
    9 Posts

    Control Loop not being interpreted properly by template builder Link to this post

    I have a control loop in a template - it's used for looping through the pagination summary for a DataObject set. Its pretty simple and works in other contexts. However in this situation it breaks i.e.

    The section of the template file looks like this:

    <% control StemData.Comments.PaginationSummary(4) %>
    <!-- Do Stuff Here -->
    <% end_control %>

    The template section it builds looks like this:

    <% control StemData.Comments.PaginationSummary(4) %>
    <!-- Do Stuff Here -->
    SSVIEWER;
    } ;
    $val .= <<<SSVIEWER

    However it should be converting it to something like this:

    SSVIEWER;
    array_push($itemStack, $item); if(($loop = $item->obj("StemData",null,true)->obj("Comments",null,true)) && ($loop = $loop->obj("PaginationSummary", array("4")))) foreach($loop as $key => $item) { ;
    $val .= <<<SSVIEWER
    <!-- Do Stuff Here -->
    SSVIEWER;
    } ;
    $val .= <<<SSVIEWER

    If I manually change it to what it should be and re-upload the cache template file the page loads fine - if I let it build it automatically it fails to make a functional template in the cache and I get:

    <b>Parse error</b>: syntax error, unexpected '}' in ...

    Any ideas - am I doing something wrong or is this a bug

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Control Loop not being interpreted properly by template builder Link to this post

    This is because SSViewer can't handle that particular syntax. If you replace <% control StemData.Comments.PaginationSummary(4) %> with <% control StemData %><% control Comments.PaginationSummary(4) %>, then have two <% end_control %>s, it should work.

  • azt3k
    Avatar
    Community Member
    9 Posts

    Re: Control Loop not being interpreted properly by template builder Link to this post

    Thanks, that worked.

    Its good to know that there is a nesting limit of one layer for control loops.

    - Just a comment if any of the devs read this -

    It does however seem a little inconsistent to me for there to be a nesting limit of one layer for control loops when you can access more deeply nested properties like Object.DataObjectSet.PrevLink etc directly without using <% control %>

    Would be nice if it were more consistent...

    as this works for $Page_Controller->DataObjectSet:

    <% control DataObjectSet.PaginationSummary(4) %>
    <!-- Do Stuff Here -->
    <% end_control %>

    And so does this for $Page_Controller->Object->DataObjectSet:

    <% control Object %>
    <% control DataObjectSet.PaginationSummary(4) %>
    <!-- Do Stuff Here -->
    <% end_control %>
    <% end_control %>

    but this doesn't for $Page_Controller->Object->DataObjectSet:

    <% control Object.DataObjectSet.PaginationSummary(4) %>
    <!-- Do Stuff Here -->
    <% end_control %>

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Control Loop not being interpreted properly by template builder Link to this post

    This was a limitation of the regex based SSViewer in 2.4 > (all methods had to be a separate expression). In the SSViewer rewrite (3.0 or master on github) this restriction should no longer apply.

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