1

I was just wondering if someone could possibly push my brain into the correct queue so that I totally get the Stash module.

I've read all the main articles on it and really like the sound of it but I'm still not quite having that magic 'Aha' moment currently.

I can see it saving me one embed tag currently on most sites I create which is obviously great however I'm absolutely positive that there's more to it than that.

I see loads of people mentioning about keeping the markup separate from the data fetching however every time I've seen this done the data is fetched at the top of a template then set as Stash variables and then lower in the template there is the markup code with the Stash variables spat out in the place where they're needed.

I'd really like to get into the DRY principle but in my head (at the moment until someone shows me otherwise [purpose of this post]) ;-) that seems pretty much the same as just placing the Channel tags and variables in with the markup. What I mean to say is that there are always going to be variables of some sort mixed in with markup so I guess I'm just not quite getting how this helps much?

I'd love it if someone could just give me a slight push in the right direction. I'm sure it won't take much but as I said before I've read all the main articles (and a fair few others) on the subject and tried it out and whilst it works great I'm just not quite having that eureka moment like I did the first time I came across ExpressionEngine.

I've got a fairly large site with many different types of pages (content types) which needs to be converted across from 1.x to the latest version of ExpressionEngine and anything I can do which can make things easier for me and going forward and that can save time then that would be great.

Hope it's okay asking this kind of question on the board here like this?

Many thanks,

Mark

1
  • Had meant to mention above that I will probably be using the Structure Module on this site too to handle all the different sections (unless there's a better way) so if there's anything here which I need to be mindful of using Stash or anything that might help me get that particular eureka moment a bit quicker because of that then I'd be extremely grateful. Thanks.
    – Mark Bowen
    Sep 8, 2014 at 8:59

2 Answers 2

1

Let me preface by saying that I've only developed a handful of EE sites and am not by any means a "seasoned" developer. At any rate, I did use Stash earlier this year on a semi-large project - similar to what you mentioned… upgrading and optimizing code etc.

As far as counting lines of code and the reasoning you mentioned, your argument is valid and hard to disagree with. For me, the preference of using stash I think deals a lot with readability and the way you process the workflow in your mind.

The buzzword that I'm sure you've heard, but seemed to really facilitate my understanding of stash, as well as the general concept, is "Injection".

Instead of including / pulling a header and footer into a "main template", you're creating a parent (skeleton?) template with various placeholders, and then your child template "injects" your code back into the parent template.

I know you mentioned you read the main articles, but I just wanted to add a couple in case you didn't see them -

EE made part of this concept native shortly after the project I worked on.

https://ellislab.com/blog/entry/template-layouts-in-expressionengine-2.8

Here's another one that I think is referenced on the Stash github page-

http://johndwells.com/blog/homegrown-plugin-to-create-template-partials-for-expressionengine

I also wanted to mention that the Stash parse option is a huge help as well. EE is constantly getting better, but I've run into a number of situations where it is outputting the wrong data, or not outputting data at all because of the native parse order. Stash is invaluable in working around these issues.

1
  • Hi Paul. Thanks for all that. I have seen those two posts yes and I can more or less 'see' that this is a good way to go but I guess just because so many people have said they are keeping their data retrieval away from the markup but I'm not really seeing that as instead of wrapping a Channel Entries tag around things we're instead using Stash variables so I'm just seeing more code than less. Obviously getting rid of embeds is a great thing and parse order is fantastic too but I'm positive there's something more fundamental that I'm missing somewhere and just can't put my finger on it.
    – Mark Bowen
    Sep 8, 2014 at 18:59
0

It sounds to me like you already have a grasp of the basics but want to delve more into the code reusability and maybe the caching aspects of Stash? I've been meaning to finish off my advanced tutorial that touches on these parts (I guess you've probably already seen parts 1 and 2? The overview section there might help too).

On large sites, Stash helps you to reuse the same markup patterns for different content and/or templates. For example if you have a complicated chunk of markup that makes up a listing item, by saving data into named variables you can reuse the exact same markup for lots of different kinds of listings. You can already achieve this natively using embeds and passing each variable as an embed variable, but this is inefficient, messy and ugly, and also doesn't allow for nested looping data, only simple strings. With Stash it just feels cleaner in my head.

As for the advantages of separating data-fetching and markup assembly instead of sprinkling channel:entries tags everywhere, For me the main advantage of this is simplified markup - all you're doing is assembling your previously saved (and cached!) variables (and nested loops for grid/relationship/category data). This approach also makes multi-layered caching possible (and also makes adding that later relatively simple).

When you mentioned that you'll be using Structure, this did set a few alarm bells ringing: if you're taking a page-based approach to assembling the site (by which I mean relying primarily on single blob of generic content for each 'page') then the advantages of Stash probably won't be so obvious, but it really comes into its own when your content is highly atomic.

1
  • Hi James. Thanks for that. Yep did see your series and it was definitely helpful but there was still (in my mind) something just not quite clicking so I think I'm just going to have to dive in with it and see where I get. Hopefully when I use it more I'll see just exactly how helpful it is going to be. Would love to see part 3 of the series when you get time to write it ;-) Thanks again for the answer though. Much appreciated.
    – Mark Bowen
    Sep 10, 2014 at 8:52

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.