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 Answer 1

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.

5
  • still not working unfortunately. Feb 27, 2019 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? Mar 1, 2019 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 Mar 2, 2019 at 0:08
  • the row in the database is still there but the value is empty Mar 2, 2019 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. Mar 4, 2019 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.