I am using the silverstripe templating and I want to loop through the child pages of the current page and dynamically input the template name in the 'include' control depending on that child's page type.
Here is the code I have so far:
<div id="tertiary-content">
<% if $Children %>
<% loop $Children %>
<% include $ClassName %>
<% end_loop %>
<% end_if %>
</div>
(I have ss files in my templates/Includes directory that relate to the $ClassName variable)
Here's the error I get:
Error was: Unknown open block "loop" encountered. Perhaps you missed the closing tag or have mis-spelled it?
I found this article from a silverstripe forum which makes me think it should work: http://www.silverstripe.org/archive/show/1023
Is it actually possible to have a variable in an include control?
Did some test and could not get <% include $ClassName %>
to work. But you could work around it with something like:
<% if $ClassName = 'SomeClass' %>
<% include SomeClass %>
<% else_if $ClassName = 'SomeOtherClass' %>
<% include SomeOtherClass %>
<% else %>
<% include DefaultClass %>
<% end_if %>
Not as pretty, but does the job.