Bug #20621 Bug Fixed

Variables with modifiers not working in conditionals without braces….

Version: 2.9.2 Reporter: Robin Sowell

This is an archived bug report. If you are experiencing a similar issue, upgrade to the latest release and if that does not solve the problem, submit a new bug report

This is with a Low Events example- see here, but it’s a general issue with variable modifies:

{exp:channel:entries}
All day: {events_field:all_day}
{if events_field:all_day == 'y'}
Yes
{if:else}
No
{/if}
{/exp:channel:entries}

That events_field:all day isn’t parsed properly- you end up with both Yes and No.

  • I can confirm this is the case with Grid variables as well. This is a showstopper for me - makes it absolutely impossible to do a conditional check on Grid columns which contain arbitrary text (as they may contain single or double quotes). Is there a hot fix I can implement?

    Derek Hogue
    28th October, 2014 at 11:51am
  • Hi Derek, can you tell me what field type and modifier isn’t working?

    Derek Jones
    28th October, 2014 at 12:22pm
  • Sure:

    {grid_field}
        {if grid_field:count == 1}<ul>{/if}
            <li>{if grid_field:text}<div class="text">{grid_field:text}</div>{/if}</li>
        {if grid_field:count == grid_field:total_results}</ul>{/if}
    {/grid_field}

    I’m also now finding that relationship tags inside of Grid columns are not parsing?

    Derek Hogue
    28th October, 2014 at 12:26pm
  • Thanks. So it’s a standard first party textarea field?

    I’m also now finding that relationship tags inside of Grid columns are not parsing?

    Did you have any problems with your update? That tells me something else may be wrong, as they definitely are working.

    Derek Jones
    28th October, 2014 at 12:30pm
  • This relationship-inside-grid problem must be similarly related:

    {book_extras:gallery limit="1"}
        <a href="http://{book_extras:gallery:title_permalink=">{book_extras:gallery:title}</a>
    {/book_extras:gallery}

    This yields:

    <a href="http://"></a>
        {/
    Derek Hogue
    28th October, 2014 at 12:30pm
  • No issue with the update, no (from 2.7.3 to 2.9.2).

    This is happening with standard text inputs, textareas, also Assets fields inside Grids (which, in fact, are being parsed and having tagdata returned even when no files are selected), etc.

    Derek Hogue
    28th October, 2014 at 12:32pm
  • "{book_extras:gallery:title_permalink="</code></pre>
    
    You have a closing brace missing there and a stray equal sign?
    
    <pre><code>"{book_extras:gallery:title_permalink}"
    Derek Jones
    28th October, 2014 at 12:34pm
  • Sorry, that code code borked somehow. Here it is again:

    {book_extras:gallery limit="1"}
        <a href="http://{book_extras:gallery:title_permalink=gallery/index}">{book_extras:gallery:title}</a>
    {/book_extras:gallery}

    Results in:

    <a href="http://"></a>
        {/
    Derek Hogue
    28th October, 2014 at 12:37pm
  • Also of note is that relationship tags are working just fine, checking all conditionals properly, etc.

    {parents channel="news" field="news_books"}{if parents:count == 1}...

    (Etc.)

    Derek Hogue
    28th October, 2014 at 12:39pm
  • Ok, all of those things are working for us; can you put in a support ticket with secure auth info so we can go in and take a look on your environment to see why it’s not working?

    Derek Jones
    28th October, 2014 at 12:39pm
  • Will do Derek.

    Derek Hogue
    28th October, 2014 at 12:45pm
  • Please update this ticket with whatever you find out, as I’m also plagued by similar issues after upgrading to 2.9. Thanks!

    Michael C. (ProImage)
    21st November, 2014 at 8:40am
  • Is your add-on up to date? I see from the other thread that you’re having an issue with Playa.

    Derek Jones
    21st November, 2014 at 9:24am
  • Closing the circle, Derek Hogue’s issue turned out to be with multiple instances of a Grid field pair.

    Derek Jones
    21st November, 2014 at 9:29am
  • Hi Derek,

    I’ve noticed that the issue in the original post above by Robin, is also affecting non-third party add-ons in EE 2.9.2.

    Here’s an example for the Search module variables.

    This doesn’t work correctly:

    Your search returned {exp:search:total_results} result{if exp:search:total_results != "1"}s{/if}

    The following does work correctly, but is using quotes and curly brackets that I’ve been trying to avoid using:

    Your search returned {exp:search:total_results} result{if "{exp:search:total_results}" != "1"}s{/if}

    Thanks,

    Stephen

    sm9
    21st November, 2014 at 9:49am
  • That’s a tag though, not a variable, so that is expected. And I’d use the tag pair version to accomplish that instead of the shortcut if you’re wanting to operate on the total conditionally.

    {exp:search:total_results}
     Your search returned {total_results} result{if total_results > 1}s{/if}.
    {/exp:search:total_results}
    Derek Jones
    21st November, 2014 at 9:56am
  • Okay thanks Derek, and thanks for that code snippet too (and fixing my broken code tags in the previous post!). 😊

    sm9
    21st November, 2014 at 10:01am
  • Is your add-on up to date? I see from the other thread that you’re having an issue with Playa.

    Derek, Playa was a few point-versions behind, but updating to the latest didn’t fix the issue. In my specific case however, upgrading to EE 2.9 apparently eliminated the need to use Playa’s var_prefix parameter to begin with, which solves this issue for me specifically.

    However, I’m still of the opinion that the var_prefix’d variables should be able to work the way I had them ({if related_entry_prefix:custom_title_field}), so I’d still love to see this issue addressed. 😊

    Michael C. (ProImage)
    24th November, 2014 at 11:31am
  • Ok sounds good Michael. For what it’s worth, they do work, the developer just needs to prep them like all other variables.

    Derek Jones
    24th November, 2014 at 11:33am
  • Open system/expressionengine/libraries/channel_entries_parser/Preparser.php and find the _find_modified_conditionals() method around line 374, and REPLACE it with this:

    public function _find_modified_conditionals()
    {
        $prefix = $this->_prefix;
        $unfiltered_all_field_names = array();
        $all_field_names = array();
    
        if (strpos($this->_tagdata, LD.'if') === FALSE)
        {
            return array();
        }
    
        foreach($this->_channel->cfields as $site_id => $fields)
        {
            $unfiltered_all_field_names = array_unique(array_merge($unfiltered_all_field_names, $fields));
        }
        
        // Do a rough cut to slim down the number of fields
        // else the string can be too long for the preg_match_all
        foreach (array_keys($unfiltered_all_field_names) as $name)
        {
            if (strpos($this->_tagdata, $name) !== FALSE)
            {
                $all_field_names[] = $name;
            }
        }       
    
        $modified_field_options = $prefix.implode('|'.$prefix, $all_field_names);
        $modified_conditionals = array();
    
        if (preg_match_all("/".preg_quote(LD)."((if:(else))*if)\s+(($modified_field_options):(\w+))(.*?)".preg_quote(RD)."/s", $this->_tagdata, $matches))
        {
            foreach($matches[5] as $match_key => $field_name)
            {
                $modified_conditionals[$field_name][] = $matches[6][$match_key];
            }
        }
    
        return array_map('array_unique', $modified_conditionals);
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases