0

Here is my code

{exp:stash:set_list name="xxxxx" parse_tags="yes"}
    {exp:channel:entries
        category="{embed:category_id}" 
        channel="xxxxx" 
        disable="categories|category_fields|custom_fields|member_data|pagination" 
        dynamic="no"
    }
            {if '{exp:plugin:that_returns_some_boolean}' == 'true'}
                {stash:item}    
                    {exp:plugin:that_returns_some_value}
                {/stash:item}
            {/if}
    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name="xxxxx"}
    {if count == 1}
        <li>
        {exp:plugin:that_returns_some_string}:&nbsp;
    {/if}

    {if item}
        {item}
        {if count != total_results}
            ,
        {/if}
    {/if}

    {if count == total_results}
        </li>
    {/if}
{/exp:stash:get_list}

The basic gist of this code block is to simply put some values in the Stash list based on some conditional.

My problem is that the conditional that wraps {stash:item} doesn't seem to be respected. {stash:item} is always appended to the list. Because of that, I see all the items outputted by {exp:stash:get_list} as if the conditional doesn't exist.

Am I doing something wrong?

1

You could try adding

 {exp:stash:set_list name="xxxxx" parse_conditionals = "yes" parse_tags="yes"}

To your initial set_list tag. You may also be better off using switchee instead of if ... Try adding the above first.

IF switchee isnt working then maybe try ifelse (also by Croxton). The issue I believe is parse order and in particular the parsing of the plugin inside the if statement, hopefully ifelse will correct the parse order issue.

{exp:stash:set_list name="xxxxx" parse_conditionals="yes" parse_tags="yes"}
    {exp:channel:entries
        category="{embed:category_id}" 
        channel="xxxxx" 
        disable="categories|category_fields|custom_fields|member_data|pagination" 
        dynamic="no"
    }
        {exp:ifelse parse="inward"} //ifelse module
            {if '{exp:plugin:that_returns_some_boolean}' == 'true'}
                {stash:item}    
                    {exp:plugin:that_returns_some_value}
                {/stash:item}
            {/if}
         {/exp:ifelse}
    {/exp:channel:entries}
{/exp:stash:set_list}
6
  • parse_conditionals="yes" made it so that nothing is outputted. Will try switchee. – developarvin Dec 30 '13 at 0:59
  • Btw, which conditional? – developarvin Dec 30 '13 at 1:14
  • Seems to me that switchee did not solve anything. – developarvin Dec 30 '13 at 2:03
  • Updated my reply :) – stuartmcd69 Dec 30 '13 at 6:39
  • It was a combination of using switchee AND setting trim="yes" to the set_list` parameter that solved the problem. I am not sure which one I should mark as the answer though. – developarvin Jan 2 '14 at 3:48
1

Try putting the conditional on the inside of the {stash:item} pair. In addition, you may need to add trim="yes" to the set_list parameters to ensure that the variable is not set to some whitespace when the condition doesn't apply. You'll also need parse_conditionals="yes" as mentioned already.

If that doesn't help, double check exactly what your plugin is returning (is it the word 'true', or is it a boolean TRUE, or 1 or 0 or yes/no etc)

2
  • It was a combination of using switchee AND setting trim="yes" to the set_list` parameter that solved the problem. I am not sure which one I should mark as the answer though. – developarvin Jan 2 '14 at 3:49
  • Mark mine for sure, James has too many points anyway ;) – stuartmcd69 Jan 2 '14 at 9:18

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.