0

Folks:

I'm wondering if there's a maximum number of if statements allowed before things fall apart.

I'm evaluating if a field has content. If no, display nothing. If yes, display whatever I say. Code:

 {if segment_2 != "product1"}
{related_entries id="product2_specifications"}
<ul>
{if max_height}<li>Maximum height - {max_height}</li>{/if}
{if weight_in_lbs}<li>Weight - {weight_in_lbs}</li>{/if}
<li>Overall length of body - {body_overall_length}</li>
<li>Overall Width - {overall_width}</li>
<li>Inside Seat Width - {inside_seat_width}</li>
<li>Inside Height - {inside_height}</li>
{if legroom_length}<li>Legroom (Length) - {legroom_length}</li>{/if}
{if height_from_ground}<li>Height (from ground) - {height_from_ground}</li>{/if}
{if folded_dimensions}<li>Folded Dimensions - {folded_dimensions}</li>{/if}
{if capacity}<li>Capacity - {capacity}</li>{/if}
{if frame}<li>Frame - {frame}</li>{/if}
{if floor}<li>Floor - {floor}</li>{/if}
{if wheels}<li>Wheels - {wheels}</li>{/if}
{if platform_base_size} <li>Platform base size - {platform_base_size}</li>{/if}
</ul>
{/related_entries}

{if:else}

{related_entries id="product1_specifications"}
<ul>
<li>Maximum payload - {max_payload_product1}</li>
<li>Weight in pounds - {weight_in_lbs_product1}</li>
<li>Overall Length - {overall_length_product1}</li>
<li>Overall Width - {overall_width_product1}</li>
<li>Frame width - {frame_width_product1}</li>
<li>Inside Box - {inside_box_product1}</li>
{if platform_base_size} <li>Platform base size - {platform_base_size}</li>{/if}
</ul>
{/related_entries}

{/if}

This code works. Now, if I add a single if statement, the whole thing fails. For example, if I add:

{if inside_height}<li>Inside Height - {inside_height}</li>{/if}

to the first part, it throws an T_ENDIF error.

I've tried the ifelse plug-in with no success.

I should also note that this is a snippet placed inside a template. Template has a Switchee switch but the error also occurs with a simple if statement.

{exp:switchee variable = "{segment_2}" parse="inward"}
{case value="product2"}
            {exp:channel:entries channel="product2_information"}  
            {product_information}
            {/exp:channel:entries}
{/case}
{/exp:switchee}

where product_information is the snippet.

Could very well be an easier way to do this. If so, let me know.

Any help would be appreciated.

3
  • Wonko, you also asked if there is an easier way. Have a read of this. github.com/croxton/Stash/wiki/Template-partials and the linked article. You obviously have created the snippet to reuse in many templates. Using the partials approach that snippet code could sit in a layout template that multiple (page) templates use. You may find it easier.
    – Lloyd Hill
    Commented Sep 18, 2013 at 19:42
  • I'm experiencing exactly the same issue, I can remove an if statement from anywhere and it starts to work. Did you resolve this Wonko?
    – user2943
    Commented Apr 7, 2014 at 12:34
  • What version of EE? Can you test without advanced conditionals? (without if:else) e.g. just use {if segment_2 != "product1"}...{/if} and another {if segment_2 == "product1"}...{/if}
    – GDmac
    Commented Apr 7, 2014 at 13:08

1 Answer 1

3

There is no maximum number of if statements. The T_ENDIF error you're getting means that there's either a malformed or unclosed conditional somewhere in your code.

First try removing your snippet from within the Switchee block to eliminate that, then remove/re-add your conditionals line-by-line to see exactly when the error starts.

1
  • This is exactly what I did. The problem is that there doesn't seem to be any point where the error starts. If I eliminate an if from no matter where, it will work. If I add an if (again, no matter where), it breaks. There doesn't seem to be a pattern.
    – Wonko
    Commented Sep 19, 2013 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.