Template Morsels 1.x

Legacy documentation for Template Morsels 1.x.

Template Morsels contains an additional feature that allows you to harvest content from Embeds. Every time you use an Embedded template in your templates, it causes a whole other set of template calls to the database for each, which results in deteriorated performance for loading the parent template.

By adding a simple parameter to your Embed tag, you can change the way EE retrieves the data. Rather than running another series of template calls, Template Morsels disables that portion and extracts the data back into your primary template and parses it inline. There is no caching involved, but this will improve site performance. Other than a few exceptions, you should be able to use this for most embedded templates.

NOTE: This is helpful for when you break up your content into Embeds for the sake of the design, but NOT when those Embeds are using template caching, PHP processing, or if you're using an Embed to elude things like variable/conditional collisions, etc. This feature will NOT work if you use it on an Embed that has an EE tag wrapped around it.

This feature consists of the following tag and parameter:

{exp:template_morsels:harvest}

{exp:template_morsels:harvest} 

To run the embed template_morsels:harvest="y" parameter, it needs to trigger the Template Morsels module in some way. If you're already using a Fetch tag in the main template, then you're set. If not, the {exp:template_morsels:harvest} tag is available to make the call.

template_morsels:harvest=

template_morsels:harvest="y" 

When used in conjunction with the {exp:template_morsels:harvest} or {exp:template_morsels:fetch} tags, this parameter allows you to harvest an Embedded template. The Embed content will be extracted into the main template and parsed accordingly.

Examples

Below is an example that shows the Harvest tag in use since there's no Morsels being fetched anywhere in the template:

{exp:template_morsels:harvest}

{embed="path_to/header" template_morsels:harvest="y"}

</head>
<body>

    <h1>The title of your page</h1>
    <p>Here is some babble...</p>

    <h3>A Lovely List of Entries</h3>
    <ul>
    {exp:channel:entries channel="articles" limit="10"}
        <li><a href="{url_title_path="news/article"}">{title}</a></li>
    {/exp:channel:entries}
    </ul>

{embed="path_to/footer" template_morsels:harvest="y"}

Or, another example, which would actually be more efficient, considering the example above used a simple Channel:Entries loop that could have been a Template Morsel (it excludes the Harvest tag since we already have a Fetch tag in there):

{embed="path_to/header" template_morsels:harvest="y"}

</head>
<body>

    <h1>The title of your page</h1>
    <p>Here is some babble...</p>

    <h3>A Lovely List of Entries</h3>

    {exp:template_morsels:fetch name="lovely_entries"}

{embed="path_to/footer" template_morsels:harvest="y"}