Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stash : Conditional Content

First off, a caveat ... I am brand new to Stash. I've heard a lot about it but this is my first time actually playing with it. I get the concept, but am having a hard time figuring this one thing out.

I have a main "wrapper" file and everything within that wrapper stays the same. I would like the option however, to be able to toggle the sidebar on and off if I need to.

I wouldn't think I would need a totally separate layout wrapper would I?

Is there a way to use a boolean variable within stash? (e.g. 2col=TRUE) or am I thinking about it wrong?

Thanks in advance for your help!

like image 535
Jacob Graf Avatar asked Nov 07 '12 20:11

Jacob Graf


2 Answers

Generally what I'd do here is setup multiple Stash gets within the wrapper. Then in your individual templates you can set both the sidebar and the main content area. For parts where you might be repeating content, like the opening and closing divs of a sidebar, you can always drop some snippets inside the stash.

You can also use exp:stash:not_empty [docs] to wrap around the div or container for your sidebar within the wrapper.

like image 191
Jeremy Gimbel Avatar answered Sep 22 '22 14:09

Jeremy Gimbel


I usually use one wrapper for every template. It'll contain an {exp:stash:get name="content"} tag, like yours, which contains the only variable content within.

In my individual templates, I embed the wrapper at the beginning using a regular EE embed ie. {embed="includes/wrapper"}.
Then I stash the content to be inserted into the wrapper using the {exp:stash:set name="content"} tag.
This seems like what you're doing anyway.

If I want to conditionally show a sidebar, I might just pass a variable into the embed.
eg. {embed="includes/wrapper" show_sidebar="yes"}

In my wrapper I would do this:

{if embed:show_sidebar}
  Sidebar stuff.
{/if}
like image 43
Jason Varga Avatar answered Sep 23 '22 14:09

Jason Varga