1

I want to save segment_3 for use on another page for each user, I think the following should work:

{exp:stash:set name="selected_category_url" scope="user" save="yes"}
   {exp:streeng slug="yes" lower="yes"}
     {segment_3_category_name}
   {/exp:streeng}x
{/exp:stash:set}

On next page:

{exp:stash:get name="selected_category_url" scope="user" save="yes"}

But this isn't working, I've tried various mixes of 'scope' 'user' in both tags, but no luck, what am I doing wrong?

1

Make sure the tag you are capturing is actually parsed before you try to save the variable, otherwise you will capture the literal tag pair rather than its output:

{exp:stash:set name="selected_category_url" scope="user" save="yes" parse="yes"}
   {exp:streeng slug="yes" lower="yes"}
     {segment_3_category_name}
   {/exp:streeng}
{/exp:stash:set}

Get it like this:

{exp:stash:get name="selected_category_url" scope="user"}

Make sure you have $config['stash_cookie_enabled'] = TRUE in your config, otherwise the user scope will be unavailable.

| improve this answer | |
  • still not working unfortunately. – greebstreebling Feb 27 '19 at 21:56
  • I think I figured why this is not working, the URL is blog/category/mobile and printing the last_segment returns 'blog'! presumably that's expected behaviour? – greebstreebling Mar 1 '19 at 21:56
  • maybe that's not why, I watched the value in the database and it's getting set once but then getting cleared – greebstreebling Mar 2 '19 at 0:08
  • the row in the database is still there but the value is empty – greebstreebling Mar 2 '19 at 0:33
  • I sounds like the value is getting overwritten. The template code that sets the variable should only be run on the initial page. The stash:get should only be run on the next page. – Mark Croxton Mar 4 '19 at 14:02

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.