I've came across a problem today where I wanted to 'inject' a stash pipe separated list of entry_ids into the entry_id parameter of a channel entries loop.
The problem wasn't to do with stash as such. I'd got my parse order correct, and stash was doing it's job as expected. The problem was that when my stash variable didn't contain any entry_ids, the channel_entries loop just output the latest entries in that channel rather than output nothing.
Here's my initial code that didn't do what I wanted:
{exp:stash:set name="recently_viewed_ids" output="no" parse_tags="yes" trim="yes"}
{exp:channel:entries channel="properties" disable="categories|member_data|pagination|trackbacks" dynamic="no" backspace="1"}{entry_id}|{/exp:channel:entries}
{/exp:stash:set}
and the channel entries loop that used the stash variable:
{exp:channel:entries
channel="properties"
entry_id="{exp:stash:get name='recently_viewed_ids'}"
limit="4"
disable="categories|member_data|pagination|trackbacks"
parse="inward"
}
{!-- display custom fields here --}
{/exp:channel:entries}
So even if recently_viewed_ids was empty, EE returned the 4 latest entries in the channel, rather than nothing.
So what's the way around this?
Jim