Skip to content

Instantly share code, notes, and snippets.

@croxton
Created August 10, 2012 16:36
Show Gist options
  • Select an option

  • Save croxton/3315420 to your computer and use it in GitHub Desktop.

Select an option

Save croxton/3315420 to your computer and use it in GitHub Desktop.
Dynamic Stash embeds using context
{!-- file at stash_templates/my_context/my_template.html --}
{!-- standard embed syntax --}
{stash:embed name="my_context:my_template"}
{!-- shortcut embed syntax --}
{stash:embed:my_context:my_template}
{!-- set embed name dynamically from a Stash variable --}
{stash:embed name="{stash:layout}"}
{exp:stash:set_value name="layout" value="my_context:my_template"}
{!-- using the static context pointer '@' --}
{exp:stash:context name="my_context"}
{stash:embed name="my_template" context="@"}
{!-- or use the pointer in the name parameter --}
{stash:embed name="@:my_template"}
{!-- for multiple cached instances of same base template, use the file_name parameter --}
{stash:embed name="another_instance_of_my_template" file_name="@:my_template"}
{!-- 'template partials' example using dynamic context --}
{stash:embed name="my_layout" context="@"}
{exp:switchee variable="{segment_1}" parse="inward"}
{!-- left to right layout for latin languages --}
{case value="en|fr|it"}
{!-- template at stash_templates/ltr/my_layout.html --}
{exp:stash:context name="ltr"}
{exp:stash:set name="content"}My language specific content{/exp:stash:set}
{/case}
{!-- right to left layout for arabic --}
{case value="ar"}
{!-- template at stash_templates/rtl/my_layout.html --}
{exp:stash:context name="rtl"}
{exp:stash:set name="content"}بلدي محتوى لغة معينة{/exp:stash:set}
{/case}
{/exp:switchee}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment