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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Control Loop not being interpreted properly by template builder


Go to End


4 Posts   1583 Views

Avatar
azt3k

Community Member, 9 Posts

26 April 2011 at 9:54am

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

Avatar
(deleted)

Community Member, 473 Posts

26 April 2011 at 11:03am

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.

Avatar
azt3k

Community Member, 9 Posts

26 April 2011 at 11:38am

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

Avatar
Willr

Forum Moderator, 5523 Posts

26 April 2011 at 8:29pm

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.