Thanks for the warm welcome Lisa.
That’s a great article series, I just read through it. It helped quite a bit and I definitely have a better idea of how the url structure affects templates in EE, thank you. While this answers many other (future) questions I’m still a little confused about how most EEers go about abstracting commonly used bits of code for items that may get displayed 50 times a page. Maybe I can explain a bit better.
Essentially what I want is a common (abstracted) “post thumbnail” embed, it would contain a title, description, author, image, maybe a rating. On a site with thousands of articles, you may display 30-40 of these posts on a page. 10 featured (at the top), 20 for the category (main body), 20 more related (sidebar). All of these posts use the exact same markup and because of this, I would like to maintain that markup in only one file. Even if there were subtle design differences I could still keep the same markup and make visual changes with CSS. What I would like to be able to do, but I’m pretty sure EE doesn’t work this way, would be:
{exp:weblog:entries weblog="default_site" limit="10"}
{embed="embeds/post_entry" entry="{entry}"}
{/exp:weblog:entries}
From there I could just magically “utilize” the entire entry object without ever calling the url structure or heavy functions. This is close to how Rails works and it’s what I’m familiar with. I’m trying to find a solid alternative in EE so that I don’t have multiple places to maintain the same code site wide, even if it is simple code.
The more I think about this I’m guessing that most EE devs are creating a few embeds that they can call on a variety of pages. Perhaps a “featured”, “post-list” or “related” embed (with these you could pass limits or restrictions), rather than looping through “post_entry” 50 times total from 3 different loops (“featured”,“posts”,“related”) within the template (like above). The “bigger embeds” method would still leave you with multiple places to maintain your markup if you need to change it but also gives you only 3 embed calls rather than 50 (unless you made embed calls from within those templates, giving you the same problem).
I believe part of my roadblock is that the “render :partial” method in rails is fairly seamless performance wise.
Is this a bit more clear? I still feel like I’m missing something. 😊 How are you guys keeping your code DRY while still avoiding 50+ embeds on a page?