Jump to:

23360 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Multiple if statements in template

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

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

Page: 1
Go to End
Author Topic: 1037 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Multiple if statements in template Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Multiple if statements in template Link to this post

    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 %>

    1037 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.