0

I have a Matrix field that includes three options. The aim is to output a <select> element if one or more of these options is selected. (These fields are Pixel & Tonic Field Pack checkboxes.)

This syntax used to work:

{if "{gold}" OR "{silver}" OR "{wood}"}
    <input type="hidden" name="on0" value="Frame Type">
    <select name="os0">
        {if gold}<option value="Gold">Gold Frame</option>{/if}
        {if silver}<option value="Silver">Silver Frame</option>{/if}
        {if wood}<option value="Rosewood">Rosewood Frame</option>{/if}
    </select>
{/if}

Now that I've upgraded to EE 2.8.1 (from a much earlier version—E 2.2) the code isn't working and I'm getting the following error:

A PHP Error was encountered
Severity: User Warning
Message: Invalid EE Conditional Variable: {if ""y"}
Filename: libraries/Functions.php
Line Number: 2640

I've tried all sorts of syntax combinations, such as removing the quotes and braces etc. The only solution I could find was pretty inefficient:

{if gold}
    <input type="hidden" name="on0" value="Frame Type">
    <select name="os0">
        {if gold}<option value="Gold">Gold Frame</option>{/if}
        {if silver}<option value="Silver">Silver Frame</option>{/if}
        {if wood}<option value="Rosewood">Rosewood Frame</option>{/if}
    </select>
{if:elseif silver}
    <input type="hidden" name="on0" value="Frame Type">
    <select name="os0">
        {if gold}<option value="Gold">Gold Frame</option>{/if}
        {if silver}<option value="Silver">Silver Frame</option>{/if}
        {if wood}<option value="Rosewood">Rosewood Frame</option>{/if}
    </select>
{if:elseif wood}
    <input type="hidden" name="on0" value="Frame Type">
    <select name="os0">
        {if gold}<option value="Gold">Gold Frame</option>{/if}
        {if silver}<option value="Silver">Silver Frame</option>{/if}
        {if wood}<option value="Rosewood">Rosewood Frame</option>{/if}
    </select>
{if:else}&nbsp;
{/if}

At least it works, but it's pretty darned ugly and inefficient. I had to put that ugly if:else at the end, too, as each of the options is optional, so to speak.

Can anyone suggest a better way to construct this?

5
  • Whilst not on topic, use 2.7 - they changed a lot in 2.8 & these little modules break. – stuartmcd69 Apr 24 '14 at 2:19
  • Hi Stuart. How easy/hard is it to go back a version? Seems like a losing battle to me to stay on older versions. Eventually you have to face the music, no? – ralph.m Apr 24 '14 at 4:33
  • If you have database backups and files its quite straight forward. You will have to manually delete/import the db & replace files - no official way to revert. I never update ro latest release and 2.8 was a major release which affected alot of addons. – stuartmcd69 Apr 24 '14 at 6:54
  • Thanks Stuart. Is there a way to acquire older versions of EE? Only the latest is offered on the EE site, so far as I'm aware. – ralph.m Apr 29 '14 at 13:34
  • Just fling EllisLab an email asking for 2.7.3 & they'll sling you a copy - will need serial. – stuartmcd69 Apr 30 '14 at 0:40
1

Not knowing what you are testing i'm assuming you are testing if the field has a value in it. So I would do this.

{if "{gold}" != "" || "{silver}" != "" || "{wood}" != ""}
      <input type="hidden" name="on0" value="Frame Type">
      <select name="os0">
          {if gold}<option value="Gold">Gold Frame</option>{/if}
          {if silver}<option value="Silver">Silver Frame</option>{/if}
          {if wood}<option value="Rosewood">Rosewood Frame</option>{/if}
       </select>
{/if}
3
  • Thanks for the suggestion, @mattsidjohn. Nice suggestion, although it still throws an error for me. I've updated the post to show the error, and also sorry for not clarifying that these are P&T checkbox options. – ralph.m Apr 24 '14 at 2:01
  • I'm assuming you have, but did you try Matt's suggestions, but without the quotes, and without both quotes and braces as well? – enga Apr 24 '14 at 17:34
  • You have ""y" in your if statement thats why its throwing the error. You can only have 2 quotes "y". – mattsidjohn Apr 30 '14 at 14:53

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.