Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did this exact thing on a client site. I re-used the same product grid across the entire site and it was 100% DRY. I used the dev branch of Stash and used the new embed feature. While regular embeds are always an option that <em>work</em>, Stash embeds are more efficient and more powerful.</p> <p>The real difference is how you pass variables, and when the embed is parsed. With stash embeds can be used inside a looping tag, and parse the data just once. (Where as regular embeds get parsed with each iteration of the loop.)</p> <p>Here is a Gist I posted a while back for another user on Twitter. <a href="https://gist.github.com/2950536" rel="noreferrer">https://gist.github.com/2950536</a></p> <p>Note, the example represents multiple files and code blocks, or I would just post here. IMO, it would make this post hard to follow and read if I posted it here. Essentially it follows a modified template partials approach.</p> <p>More information on template partials. <a href="http://eeinsider.com/blog/ee-podcast-stash-template-partials/" rel="noreferrer">http://eeinsider.com/blog/ee-podcast-stash-template-partials/</a></p> <p>But to more directly answer the question of, "How does one replace embed variables with Stash?". The solution is rather simple and based on core programming concepts of "setters" and "getters".The theory is, if one sets a variable it can be retrieved at any later point in the template. The trick is settings the variables before the getters are parsed.</p> <pre><code>{exp:stash:set} {stash:page_content} {exp:channel:entries channel="your-channel"} {stash:your_var_1}Some value 1{/stash:your_var_1} {stash:your_var_2}Some value 2{/stash:your_var_2} {stash:your_var_3}Some value 3{/stash:your_var_3} {stash:your_var_4}Some value 4{/stash:your_var_4} {stash:embed name="your-template" process="start"} {/exp:channel:entries} {/stash:page_content} {/exp:stash:set} {stash:embed name="header" process="end"} </code></pre> <p>That's where the <em>process</em> parameter comes into play. This will allow you to embed your template <em>before</em> the entries loop is ran, and to embed the header which would contain the site wrapper and output the page content. Once you get the hang of it, it becomes really powerful and makes your sites so much cleaner.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload