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.

All other Modules

Discuss all other Modules here.

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

Conditional logic


Reply

2 Posts   1207 Views

Avatar
Junglefish

14 October 2010 at 10:59pm Community Member, 104 Posts

What's wrong with this code?

               <% if InSection(administrative-news) %>
                  administrative-news
               <% else_if InSection(image-galleries) %>
                  image-galleries
               <% else %>
                  ... alternative content ...
               <% end_if %>

When the first conditional is true, this is what prints to the browser:
"administrative-news <% else_if InSection(image-galleries) %> image-galleries"

When the second conditional is true, this is what prints to the browser:
"... alternative content ..."

It's like the "else_if" clause is being interpreted as a string(!) What am I doing wrong?

jf/

Avatar
datswicked

24 June 2012 at 9:05pm (Last edited: 24 June 2012 9:07pm), Community Member, 15 Posts

I believe you have to nest your if's as they don't work multi level (if, else if, else if, else) like php, only support 1 level (if, else) in templates..

ie i have done this as part of a product template and it works ok, bit of a hack but it works..

<% if Level(5) %>
   <!-- 5: PRODUCT -->
   <% include prod_aCatProd %>
<% else %>
   <% if Level(4) %>
      <!-- 4: PRODUCT LISTING.. -->
      <% include prod_aCategory4 %>
   <% else %>
      <% if Level(3) %>
         <!-- 3: STORAGE -->
         <% include prod_aCategory3 %>
      <% else %>
         <% if Level(2) %>
            <!-- 2: LANDING -->
         <% end_if %>
      <% end_if %>   
   <% end_if %>
<% end_if %>

so you should have

<% if InSection(administrative-news) %>
administrative-news
<% else %>
<% if InSection(image-galleries) %>
image-galleries
<% else %>
... alternative content ...
<% end_if %>
<% end_if %>

then it will check the admin news first then the image galleries and then alternative content last

hope that helps. I know this is an old post but i came across it with no answer and hopefully it helps someone..