3

So I have the following code snippet which is working fine:

{exp:stash:set name="market_ids" parse_tags="yes"}
{exp:query sql="select GROUP_CONCAT(entry_id SEPARATOR '|') as market_ids from exp_channel_data where channel_id=3 AND field_id_12 LIKE CONCAT('%', DAYNAME(from_unixtime({exp:stash:delivery_day})), '%')" parse="inward"}
    {market_ids}
{/exp:query}
{/exp:stash:set}

This sets a value for the markets that I use later on in the page.

However, sometimes the stash value inside the SQL statement ({exp:stash:delivery_day}) wont be set. Typically if the user has clicked a link and not entered the site through our pre-determined route.

I've tried adding a conditional around whole statement, but it doesn't appear to be working because it's still executing the SQL statement:

{exp:stash:set name="market_ids" parse_tags="yes"}
{if "{exp:stash:not_empty name='delivery_day'}"}    
{exp:query sql="select GROUP_CONCAT(entry_id SEPARATOR '|') as market_ids from exp_channel_data where channel_id=3 AND field_id_12 LIKE CONCAT('%', DAYNAME(from_unixtime({exp:stash:delivery_day})), '%')" parse="inward"}
    {market_ids}
{/exp:query}
{/if}
{/exp:stash:set}

Anyone offer any advice on the best way to get this working?

3 Answers 3

2

Have you tried adding parse_conditionals="yes" to the set parameters? Alternatively, reversing the wrapping to put the conditional on the outside of the set tags?

1

You could just do this to check the delivery_day value.

{if "{exp:stash:delivery_day}" != ""} 
  ... your code ...
{/if}
0

If you use {switchee} on stash:delivery_day you can even have a {case} to display something when the delivery day was not set:

{exp:switchee variable="stash:delivery_day" parse="inward"}
  {case value=""}
    No delivery day set
  {/case}
  {case default="yes"}
    ...do query...
  {/case}
{/exp:switchee}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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