0

I have this code.

{exp:channel:entries
    author_id="{segment_3}"
    channel="images"
    disable="categories|category_fields|pagination"
    dynamic="no"
}
    {if no_results}
        {exp:stash:set name="default_image"}http://placehold.it/200x200/{/exp:stash:set}
    {/if}

    {if count == 1}
        {exp:stash:set name="default_image"}{image}{/exp:stash:set}
    {/if}

    {if is_default == 'yes'}
        {exp:stash:set name="default_image"}{image}{/exp:stash:set}
    {/if}
{/exp:channel:entries}

The goal of the logic here is to get default image. Here is the logic

  1. If there are no results, use a default image
  2. If there is only 1 profile image, use it as default image
  3. If there is a default image set, use it as a default image

I try to use Stash to make this happen but outputting the contents of

{exp:stash:get name="default_image"}

returns a blank string.

Am I doing something wrong with Stash? Is it even possible to do it?

1 Answer 1

1

I see what you're trying to do and you're close, as most things it's a parse order issue, so some simple refactoring should suffice…

{exp:stash:set name="default_image" parse_tags="yes" parse_conditionals="yes"}
//Set stash here, so it parses conditionals
  {exp:channel:entries
    author_id="{segment_3}"
    channel="images"
    disable="categories|category_fields|pagination"
    dynamic="no"
}
    {if no_results}http://placehold.it/200x200/{/if}
    {if count == 1}{image}{/if}//This could do with some thought - '1' & 'is_default' could be similar, if not the same and may cause issues.
    {if is_default == 'yes'}{image}{/if}
  {/exp:channel:entries}
{/exp:stash:set}

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.