Search code examples
expressionengine

expression engine: do I use snippets or embedded templates for the sidebar in my blog


I have a website created using codeigniter framework. I am using expression engine cms to create a blog on that site from scratch. With the idea that I will land up using expression engine for the rest of the site and pages as well - one thing at a time.

I would like to have links to testimonials, ebooks, recent posts etc show up on my sidebar. (Testimonial and ebook pages have yet to be created and will be creating it with expression engine). I would like to use these elements through out my site separately as in i would like to use testimonials code maybe on a page and use my ebooks code on another page for example.

With that in mind, how should I create a sidebar elements for the blog - should i use snippets each of them testimonial, ebooks, sign up form, recent posts etc or just create an embedded template. Is there a better way to do this so I can reuse this content all round the site once the conversion is complete - speaking from a performance perspective.


Solution

  • At its most basic, I'd use a snippet for your whole sidebar. That way you can just call it quickly from your templates via {sidebar} or whatever. Snippets have very low overhead.

    What I sometimes do if I need more flexibility - to only display certain "modules" of my sidebar depending on my template, for instance - is instead do an embed of my sidebar from embeds/.sidebar (just an example), and turn on/off particular bits using embed variables:

    {embed="embeds/.sidebar" testimonials="y" recent_posts="y"}

    Then in your .sidebar.html template:

    {if embed:testimonials}
        // testimonials code goes here
    {/if}
    
    {if embed:recent_posts}
        // Recent posts code goes here
    {/if}
    

    This method has greater overhead (embeds always do), but it lets you determine, per-template, what to include in the sidebar.