1

I'm using a simple grid conditional to show academic references in a post. I only want to show it if someone has entered some references, but the conditional just isn't working. What am I doing wrong?

My code is:

{if references:total_rows > 0}
    <h5>Further Reading</h5>
    <ul>{references}
    <li>{references:names}, {references:pub-year}, {references:title-work}, {references:publisher}, {references:country} </li>
    {/references}</ul>
{/if}

I've also tried using " and brackets to surround the if condition but that doesn't work either.

0

This is a known bug in EE 2.9. If you're using modifiers in conditionals, use the (otherwise not recommended) quoted-braced syntax instead:

{if "{references:total}" > 0} ... {/if}
2
  • thx, I did try this previously as had seen the issue elsewhere on here... it didnt work. Ill try it again to make sure – Boshy Jan 7 '15 at 10:25
  • UPDATE: Yes this appears to be the only way I can get the refs to show up if they are there, they will not show without the 'quoted-braced' code. When I tried doing this before I must've done it the wrong way round (brace/quote not quote/brace). My other stupid mistake was setting the field grid minimum row to 1, and presuming that if it was empty it wouldn't show up - of course it does as activates any text that might present in the conditional code even though the row is empty - silly mistake. – Boshy Jan 8 '15 at 12:55
1

Should that conditional even be needed? The tag pair shouldn't return anything if there isn't at least one row, so could you not simply do something like this:

{references}
{if references:count == "1"}<h5>Further Reading</h5><ul>{/if}
<li>{references:names}, {references:pub-year}, {references:title-work}, {references:publisher}, {references:country} </li>
{if references:count == references:total_rows}</ul>{/if}
{/references}
3
  • That has always left a space/gap when nothing exists when I have tried. ;) – W3bGuy Jan 7 '15 at 0:12
  • Ot shouldn't leave a thing in the template at all with the way I have it set up here - the h5 and opening ul only get inserted if there are entries, and likewise the closing </ul> only gets inserted after the last entry (which doesn't exist if there are no entries). And everything in between would also only be inserted for each entry found, which if zero, would result in no output at all between the tag pair, just like an entries loop. – Jean St-Amand Jan 12 '15 at 15:37
  • I agree that it shouldn't, but it has in previous installations for me. I have had to perform various workarounds. It may just be due to some of the "buggy" releases that have been let out by Ellis in the past. ;) – W3bGuy Jan 12 '15 at 17:35
0

I am using this code in EE2.9 without the quotes and am having zero issues. The issue @Low is referring to is when you are comparing the variable as a string. AFAIK

{if service_page_copy:total_rows > 0}
    {service_page_copy}
        {if "{service_page_copy:headline}" != ""}
            <h4>{service_page_copy:headline}</h4>
        {/if}
        {if "{service_page_copy:copy}" != ""}
            {service_page_copy:copy}
        {/if}
    {/service_page_copy}
{/if}

I have run into a couple of oddities in the past. The only thing I can think of that you may want to try is this:

  1. Try changing the name of your field to make sure it isn't a reserved or conflicting name.
  2. Try changing your names from '-' hyphens to '_' underscores to see if that resolves your issues.

If not, let me know and I can try to replicate it on a local test environment. :)

1
  • ok Ill try this and let you know... – Boshy Jan 7 '15 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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