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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Multiple if statements in template


Go to End


2 Posts   1781 Views

Avatar
DeklinKelly

Community Member, 197 Posts

2 December 2010 at 2:36pm

My template code gives an error. The problem is that I have multiple conditionals in the template.

        <% if Row3Heading || Row3Image || Row3Content || Row3LinkText %>
        <div class="bottomColumn">
        <% if Row3Heading %>
          <h1>$Row3Heading.Parse(NiceXHTML)</h1>
        <% end_if %>

        <% if Row3Image %>
          <p class="shadow"><% if Row3LinkURL %><a href="$Row3LinkURL.ATT"><% end_if %><img src="<% control Row3Image %>$SetWidth(250).Link<% end_control %>" alt="" title="" /><% if Row3LinkURL %></a><% end_if %></p>
        <% end_if %>

        <% if Row3Content %>
        <p class="text">$Row3Content.Parse(NiceXHTML)</p>
        <% end_if %>

        <% if Row3LinkURL && Row3LinkText %>
          <h2><a href="$Row3LinkURL.ATT">$Row3LinkText.Parse(NiceXHTML)</a></h2>
        <% end_if %>
        </div>
        <% end_if %>

How can I use more than one set of || in the template?

Avatar
Willr

Forum Moderator, 5523 Posts

2 December 2010 at 3:34pm

Template engine doesn't support that level of checking. You'll have to write that logic in your PHP code

function ShowBottomColumn() {
return ($this->Row3Heading || $this->Row3Image || $this->Row3Content || $this->Row3LinkText);
}

Then just use <% if ShowBottomColumn %>