Jump to:

23477 Posts in 18941 Topics by 2878 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: 1060 Views
  • DeklinKelly
    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 %>
    <% 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 %>
    <% end_if %>

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

  • Willr
    Forum Moderator
    5502 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 %>

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.