I have this kind of code structure. foo and bar are both Grid fields.

{if "{foo:total_rows}" > 0 OR "{bar:total_rows}" > 0}
  {if "{foo:total_rows}" > 0}
       {foo}
          {foo:a}
          {foo:b}
          {foo:c}
       {/foo}
  {/if}
{/if}

The problem is that {foo:a},{foo:b} and {foo:c} is not outputting anything.

However, when I do this

{if "{foo:total_rows}" > 0 OR "{bar:total_rows}" > 0}

   {foo}
      {foo:a}
      {foo:b}
      {foo:c}
   {/foo}

   {if "{foo:total_rows}" > 0}
        {foo}
           {foo:a}
           {foo:b}
           {foo:c}
        {/foo}
    {/if}
{/if}

I get

{foo}{/foo}abc

a, b, and c are the contents of {foo:a},{foo:b} and {foo:c} respectively.

What is the problem here? Is this a parse order issue?

Looks odd that {foo} is not recognised at first.

Have you tried modifying

{if "{foo:total_rows}" > 0}

It looks like you could be comparing a string to a number. What does

{if {foo:total_rows} > 0}

give you?

Also, what happens if you test removing the outer if?

This could be related to a bug that causes PREG_BACKTRACK_LIMIT_ERROR when parsing tag pairs. Essentially the regular expression thats used to find chunks of the template by pairing opening and closing tags doesn't perform efficiently enough in some cases. Here is the bug report.

The bug report contains a work around that may work for you. In system/expressionengine/libraries/api/Api_channel_fields.php change line 1852 (this line number is from the 2.9.2 codebase, so it may differ, should be within the get_pair_field function) to:

if (preg_match("/".LD."{$field_name}((?::[^\s}]+)?)(\s.*?)?".RD."(.*?)".LD.'\/'."{$field_name}\\1".RD."/s", $tagdata, $matches, 0, $offset)) 

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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