0

I was successfully using the following block of code until I upgraded to EE 2.9.0.

{exp:query sql="SELECT COUNT( * ) AS itemCount FROM exp_freeform_form_entries_4 WHERE form_field_52 = 'yes'"}
        {if 15 > {itemCount}}
                  <td><label for="setup_1">Mon. Dec. 9, Setup/iron - 9am-noon: {exp:query sql="SELECT 15 - COUNT( * ) AS itemNeeded FROM exp_freeform_form_entries_4 WHERE form_field_52 = 'yes'"}{itemNeeded}{/exp:query} needed </label>
                  <input type="checkbox" name="setup_1" id="setup_1" value="Yes" /></td>
        {if:else}
            <td>Monday 9-noon is full</td>
        {/if}
    {/exp:query}

Now however I get the following error message when I try and load the page:

Error

You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

Parser State: Unexpected end of Template “apex/volunteer-form” on line 2; expected ENDIF tag for opening on line 1.

I have carefully checked the page and don't see any missing {/if} or }. Any suggestions for what I am missing here?

  • Did you try removing the brackets from "{if 15 > {itemCount}}" to "{if 15 > itemCount}" OR to "{if 15 > '{itemCount}'}"?? – Mark Busnelli Jr Oct 6 '14 at 19:40
  • Mark, I did try both of those, but without success. That is where the problem is, because if I replace {itemCount} with a number like 6, the error goes away. Is there another way to do itemCount? – forrest Oct 6 '14 at 19:51
  • And you verified that itemCount is in fact outputting? I thought there was a conditional bug reported with 2.9 but I can't find it :// did you try upgrading to 2.9.2? – Mark Busnelli Jr Oct 6 '14 at 19:58
  • Yes it does provide an output and does not through an error, unless I put it inside the if statement. – forrest Oct 6 '14 at 20:10
0

I did some experimenting and with some leading questions from Mark was lead to discover that {itemCount} needs to be inside of quotes but not inside of { }.

So the final solution is:

{exp:query sql="SELECT COUNT( * ) AS itemCount FROM exp_freeform_form_entries_4 WHERE form_field_52 = 'yes'"}
        {if 15 > "itemCount"}
                  <td><label for="setup_1">Mon. Dec. 9, Setup/iron - 9am-noon: {exp:query sql="SELECT 15 - COUNT( * ) AS itemNeeded FROM exp_freeform_form_entries_4 WHERE form_field_52 = 'yes'"}{itemNeeded}{/exp:query} needed </label>
                  <input type="checkbox" name="setup_1" id="setup_1" value="Yes" /></td>
        {if:else}
            <td>Monday 9-noon is full</td>
        {/if}
    {/exp:query}

With the conditional as:

{if 15 > "itemCount"}
| improve this answer | |
  • Ahh haa! Happy to hear you got it sorted out. – Mark Busnelli Jr Oct 6 '14 at 20:29

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.