1

I'm trying to get a Channel entry made by a particular member id (there will always be just 1 entry) and store it in a Stash variable:

{exp:channel:entries
    author_id="{segment_2}"
    channel="profiles"
    disable="categories|category_fields|custom_fields|member_data|pagination"
    dynamic="no"
}
    <h4>Works: {entry_id}</h4>
    {exp:stash:entry_id}{entry_id}{/exp:stash:entry_id}
    <h4>Works: {exp:stash:entry_id}</h4>
{/exp:channel:entries}

<h4>Does NOT Work: {exp:stash:entry_id}</h4>

Why do I not have access to the Stash variable's value outside the loop?

My ultimate goal is to use that variable in another loop:

{exp:channel:entries
    channel="profiles"
    disable="categories|category_fields|member_data|pagination"
    entry_id="{exp:stash:entry_id}"
    limit="1"
}

(I'm already worried I'll run into parse order issues.

5

The reason you do not have access to that variable outside the loop is because your stash tags (getters and setters) are not parsed at the same time. EE module tags are parsed recursively from the outwards inwards, peeling them one after another like a oignon.

In your code above, your stash set tags are inside an entry loop (level 2), while your get tag is at the root (level 1). That means your get tags are still empty when processed.

Solution One:

Use process=end on your getter to force it to be processed later than your setter

With a single value:

{exp:channel:entries channel="blogposts" disable="categories|category_fields|custom_fields|member_data|pagination" dynamic="no" limit="1"}
        {exp:stash:st_entryid}{entry_id}{/exp:stash:st_entryid}
{/exp:channel:entries}

<p>Stash output entry id: {exp:stash:st_entryid process="end"}</p>

With a list

{exp:channel:entries channel="blogposts" disable="categories|category_fields|custom_fields|member_data|pagination" dynamic="no" limit="5"}
    {exp:stash:append_list name="st_blogposts_ids" parse_tags="yes"}
        {stash:st_entryid}{entry_id}{/stash:st_entryid}
    {/exp:stash:append_list}
{/exp:channel:entries}

{exp:stash:get_list name="st_blogposts_ids" parse_conditionals="yes" process="end"}
    {if count == 1}<ul>{/if}
        <li>Entry ID: {st_entryid}</li>
    {if count == total_results}</ul>{/if}
{/exp:stash:get_list}

Solution Two:

Put the setters and the getters on the same "oignon" layer by wrapping your setters around the channel entries tag. That's usually the method I use whenever possible. With lists, you have the added value that the performance of {exp:stash:set_list} is better than {exp:stash:append_list}

Single value:

{exp:stash:st_testid parse_tags="yes" trim="yes"}
    {exp:channel:entries channel="blogposts" disable="categories|category_fields|custom_fields|member_data|pagination" dynamic="no" limit="1"}
            {entry_id}
    {/exp:channel:entries}
{/exp:stash:st_testid}

<p>Stash output entry id: {exp:stash:st_testid}</p>

List:

{exp:stash:set_list name="st_test_ids" parse_tags="yes"}
    {exp:channel:entries channel="blogposts" disable="categories|category_fields|custom_fields|member_data|pagination" dynamic="no" limit="5"}
            {stash:st_entryid}{entry_id}{/stash:st_entryid}
    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name="st_test_ids" parse_conditionals="yes"}
    {if count == 1}<ul>{/if}
        <li>Entry ID: {st_entryid}</li>
    {if count == total_results}</ul>{/if}
{/exp:stash:get_list}

Hope that helps.

| improve this answer | |
0

Not sure if this is the most trim way to do what you're asking, but it should work:

{exp:stash:set_list name="cached_entryid" parse_tags="yes"}
    {exp:channel:entries
        author_id="{segment_2}"
        channel="profiles"
        disable="categories|category_fields|custom_fields|member_data|pagination"
        dynamic="no"
    }
        {stash:eid}{entry_id}{/stash:eid}
    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name='cached_entryid'}
    {exp:channel:entries
        channel="profiles"
        disable="categories|category_fields|member_data|pagination"
        entry_id="{eid}"
        limit="1"
    }
        ENTRY ID: {eid}
    {/exp:channel:entries}
{/exp:stash:get_list}

Uses set_list instead of set.

| improve this answer | |
0

You can probably wrap the channel entries loop with stash tags, like this:

{exp:stash:set parse_tags="yes"}
  {exp:channel:entries ...}
    {stash:entry_id}{entry_id}{/stash:entry_id}
  {/exp:channel:entries}
{/exp:stash:set}

{exp:stash:get name="entry_id"}
or {exp:stash:entry_id}
| improve this answer | |

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.