1

This is my setup. My URL my-site/index.php/group/template-x

Template-x must call two different pieces of code. I want that to happen by using the third segment, which shall be NL or BE. So my-site/index.php/group/template-x/NL or my-site/index.php/group/template-x/BE.

The two pieces of code are stored as Stash Templates. The names are consumenten-NL.html and consumenten-BE.html. I can show the code by calling them hard coded, like {stash:embed:registration:consumenten-NL} but I want to use segment_3 dynamically.

In template-x I can grab segment-3.

{exp:stash:set name="segment-3"}{segment_3}{/exp:stash:set}

and show it in the template

{exp:stash:get name="segment-3"}

Now calling the embeds in template-x:, I do not seem to be able to do this:

{stash:embed:registration:consumenten-{exp:stash:get name="segment-3"}}

gives

error
Stash: the file "../stash_templates/registration/consumenten-M40o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr.html" was not found.

I tried several other methods, but the documentation is too high for me, so I ask for a little assistance here. Much appreciated.

Thanks.

1

Maybe I've misunderstood, but why make segment_3 a stash variable? It's already an early-parsed global variable. Thus:

{stash:embed:registration:consumenten-{segment_3}}
1
  • It has been a while since, and I forgot to complete this. Thanks, Mark, you made me think and we decided for a complete different setup. But the answer of Robson Sobral was very informative. I remembered his comment on another occasion, so thanks for that as well. – Hansl Jan 7 '14 at 12:14
2

Is the both occurrences of {exp:stash:get name="segment-3"} on the same template? In this case, I know how to fix this.

This is a trick peculiarity of eecms template parser that sometimes bites us.

The template parser, when fount some tag to parse, looks for all another instances of the same tag, with the same parameters and the same content on the template and replaces every one of them by a temporary marker, to avoid to parse the same code more than once.

In your case, {exp:stash:get name="segment-3"} is being replaced by M40o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr. So:

{exp:stash:get name="segment-3"}
[...]
{stash:embed:registration:consumenten-{exp:stash:get name="segment-3"}}

Become:

M40o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr
[...]
{stash:embed:registration:consumenten-M40o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr}

Then, the parser founds {stash:embed:registration:consumenten-M40o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr} and replaces it by another marker.

In the time of parsing the first tag, its occurrence inside the second one isn't there yet, so it remains not parsed.

The solution is to prevent this "caching" on the second occurrence. Try this:

{stash:embed:registration:consumenten-{exp:stash:get name="segment-3" random}}

random is an undocumented parameter that sometimes saves the day. Just use it when you really need it!

You can read about it here, here and here.

1

You may just need to add process="end" to your stash embed tag:

{embed:stash:registration:consumenten-{exp:stash:get name="segment-3"} process="end"}

UPDATE

Two more options.

  1. Don't store segment_3 in stash since it's already a global variable. Use {segment_3} in your stash embed tag instead.

    {embed:stash:registration:consumenten-{segment_3} process="end"}

  2. Use set_value (docs) tag in template-x.

    {exp:stash:set_value name="segment-3" value="{segment_3}" parse="inward"} {embed:stash:registration:consumenten-{segment-3} process="end"}

UPDATE 2

Try putting double quotes around {segment_3} like this:

{embed:stash:registration:consumenten-"{segment_3}" process="end"}
{!-- OR without process parameter --}
{embed:stash:registration:consumenten-"{segment_3}"}
3
  • I am sorry, unfortunately that does not help. Your code results in NL process="end"} – Hansl Oct 27 '13 at 7:51
  • Thanks for thinking with me! I tried this before, {embed:stash:registration:consumenten-{segment_3} process="end"} it just returns NL (=value of segment_3. Now for {exp:stash:set_value name="segment-3" value="{segment_3}" parse="inward"} {embed:stash:registration:consumenten-{segment-3} process="end"} this results in NL process="end"} – Hansl Oct 27 '13 at 8:29
  • What version of Stash do you have. Also, can you add to your original question what output you expect (what's in /consumenten-NL)? – Stephen Callender Oct 27 '13 at 10:43

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.