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.

Archive /

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

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

conditional html in templates


Go to End
Reply


2 Posts   1457 Views

Avatar
MrElf

Community Member, 9 Posts

5 September 2008 at 9:49am

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 %>
<h2>$Industry</h2>
$lastindustry = $Industry
<% end_if %>
<p>$Title - $CompanyName</p>
<% end_control %>
</div>

How best to achieve this?

Avatar
Willr

Forum Moderator, 5521 Posts

5 September 2008 at 3:52pm

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 %>
<h2>$Title</h2>
<% 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