Q:

Stash variable is being set but I can't retrieve it

I'm trying to create a stash variable of a pipe delimited entry_id list using the following:
{exp:channel:entries channel="related_entries" limit="1" disable="categories|member_data|pagination|trackbacks" entry_id="2249"}
{exp:stash:set name="featured_ids" parse_tags="yes"}
    {entry_relationships backspace="1" parse="inward"}{entry_id}|{/entry_relationships}
{/exp:stash:set}

{/exp:channel:entries}
I've enabled template debugging and can see that the variable is being set by stash:
Stash: SET featured_ids to value 6147|8116|6270|3031|3019|463|6380

..but when I try and retrieve the variable using
{exp:stash:get name="featured_ids"}

I get
Stash: RETRIEVED featured_ids with value 

and looking at the order of the output, guess what? It is LATER in the parse order than setting the variable in the first place, which explains why it doesn't output anything.
Does anyone know how I can get around this?
EDIT: I've added process="end" to my get tag and now in the template debugging I'm seeing the following:
Stash: RETRIEVED featured_ids with value 6147|8116|6270|3031|3019|463|6380

but when I look at the output on the actual page, I'm seeing:
{b0faccac1d7de314625221c0189105071802790178}

Anyone any ideas?
Cheers
Jim

A:

The original problem arises from the way that module tags are parsed by EE, from the outwards in. The outer layer of tags is parsed, then the next layer underneath, and so on: much like peeling an onion. In your case the {exp:channel:entries} tag and the {exp:stash:get} tag are on the outer layer, while the {exp:stash:set} is on the inner layer.
You tried to solve this, correctly, using process="end" parameter when you get the variable - but you saw a random string output. In this case it's NOT the famous M00.. string used as a cache placeholder by ExpressionEngine. Instead that string is a placeholder generated by Stash used to mark a position in the template for a variable; it gets replaced at the end of template processing by an extension triggered by the template_post_parse hook. 
Of course, if you don't have the Stash extension installed then the placeholder never gets replaced and you see that string. So you simply need to install the extension :)

A:

EDIT 1: Not that, see Mark's reply below for an in depth explanation
Might be an EE caching issue. If using the same tag more than once, try to add 'random' at the end of your get tag to stop EE from caching it.
{exp:stash:get name="featured_ids" random}

EDIT 2: tried to reproduce
Well, I tried on a sandbox install and the following code works
{exp:stash:set name="featured_ids" parse_tags="yes" trim="yes"}
    {exp:channel:entries disable="categories|category_fields|member_data|pagination|trackbacks" channel="news" status="open" dynamic="no" orderby="date" sort="desc" limit="500" backspace="1"}
        {entry_id}|
    {/exp:channel:entries}
{/exp:stash:set}

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

So, I would try to move the set tags outside of the channel entries tags like so:
{exp:stash:set name="featured_ids" parse_tags="yes" trim="yes"}
    {exp:channel:entries channel="related_entries" limit="1" disable="categories|member_data|pagination|trackbacks" entry_id="2249"}
        {entry_relationships backspace="1"}{entry_id}|{/entry_relationships}
    {/exp:channel:entries}
{/exp:stash:set}

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

Any better ?

