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.


Our old forums are still available as a read-only archive.

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

conditional html in templates


2 Posts   1303 Views


5 September 2008 at 9:49am Community Member, 9 Posts

In my sample example I have a collection of members who are sorted by industry ( a text field) What I want to do is have a conditional header that is displayed when the industry group changes.

This is an outline of what I want to do.

      <div id="MemberList">
         <% control MemberList %>
            <% if $lastindustry <> $Industry %>
               $lastindustry = $Industry
            <% end_if %>
            <p>$Title - $CompanyName</p>
         <% end_control %>

How best to achieve this?


5 September 2008 at 3:52pm Forum Moderator, 5511 Posts

the template parser is pretty basic in what you can do, eg you cant assign variables and change $lastIndustry inside the template.

What you would need to do is change your datamodel a bit for the template so you have a DataObjectSet of Industries. Then each industry has a DataObjectSet of Members so in the template you would do

<% control Industries %>
<% control IndustryMembers %>
$Title - $CompanyName
<% end_control %>
<% end_control %>

And so your PHP method Industries() would need to make a DataObjectSet of all the Industries then for each Industry generate a list of members for it