Reputation: 1941
I'm building a single page portfolio with SilverStripe.
So far I am able to loop through my sites and all $Title[s] and $Content[s] are visible in one <div>
. Now I want to attach a certain CSS-class if the current page (which is looped) is named "Contact".
Something like:
//Pseudocode:
<loop start>
if ($Title == 'Contact') <div class="a"></div> else <div class="b"></div>
<loop end>
Does anybody know how to do this?
Upvotes: 1
Views: 1421
Reputation: 1809
you could try a custom getter method such as :
function DivClassName() {
return $this->Title == 'Contact'?'a':'b';
}
and use the following in your template.
<div class="$DivClassName"></div>
keeps the logic out of your templates :)
Upvotes: 1
Reputation: 14244
<% if Title = "Contact" %>
<div class="a"></div>
<% else %>
<div class="b"></div>
<% end_if %>
Upvotes: 0