5

We have a Matrix that has a simple text input in the first column, and another text input in the second column. First column is for a link title, second column is for a URL. This is the stripped down code we're using to display this information on the template, showing the title if there is one:

{if "{link_field:total_rows}" >= 1}
  <h4>{title} Links</h4>

  <ul>{link_field}
    <li>
      <a href="{link_url}">{if link_title}{link_title}{if:else}{link_url}{/if}</a>
    </li>
  {/link_field}</ul>
{/if}

Very simple: if there are any rows, output the h4, open a UL, loop through the rows (outputting a title if there is one, otherwise outputting the URL), close the UL, done.

The issue is that the simple "if" conditional is breaking things, especially if there is any text in the first column that resembles user-related global variables (email, screen_name, username). Those are actually getting parsed - even though there are no braces.

For example, a link title might read "Send email to user-selected recipient". The 'email' there is getting parsed (and getting double quotes added) so the field reads (using my email address): "Send "ryan@masugadesign.com" to user-selected recipient". That being the case, it's going into the {if link_title} conditional statement and breaking, so that the template returns a parse error:

Parse error: syntax error, unexpected T_STRING in /.../system/expressionengine/libraries/Functions.php(680) : eval()'d code on line 649

If we just output {link_title} outside of a conditional, it outputs the text in the field as I'd expect. Another odd thing we notice is that if we put a plus sign "+" in the first column, the template breaks as well.

Doesn't seem to make a difference how we do that conditional:

{if link_title}
{if link_title != ''}
{if "{link_title}"}
{if "{link_title}" != ''}

Has anyone run into this? This site is on EE 2.5.2. We just updated and tested with latest version of Matrix (2.5.3), so the add-on version doesn't seem to matter.

5
  • {if '{link_title}'} works, but then breaks on any single quotes inside of {link_title}. – Dave DeHaan Mar 12 '13 at 17:10
  • Ryan, have you checked if those variables are getting parsed in a normal textarea? There are some standard global variables that can be used in those entries, and you may be running into them... – Lisa Mar 12 '13 at 17:38
  • it looks like it's intended behavior by EE -- the matrix field outputs the string "Developer email address" (as an example), then we did a conditional of {if "developer email address"} -- since global variables are just about the last thing parsed, it parsed email to be the addon developer's email, resulting in a conditional of {if "developer "david@masugadesign.com" address"}, causing a php error. – Dave DeHaan Mar 12 '13 at 17:52
  • That's sort of lousy news. All anyone has to do is enter any of a handful of "reserved" variable names (and such a common word like "email" - it's unfortunate that isn't prefixed with anything like exp_email, for example) and we output that variable in a conditional and boom, broken template(s). We'll have to police every entry. – Ryan Masuga Mar 12 '13 at 20:13
  • In this case, the word "email" doesn't even have braces on it - perhaps because it is showing up inside the "if" statement, EE sees it as having braces and tries to parse it? – Ryan Masuga Mar 12 '13 at 20:21
1

There were some weird conditional bugs in 2.5.2 that got fixed - may be worth upgrading:

http://ellislab.com/forums/viewthread/223416/

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.