Template Morsels 1.x

Legacy documentation for Template Morsels 1.x.

The Template_Morsels:Fetch tag allows you to fetch morsels of code from your cache to placed into a template. The tag is clean and simple. In most cases, just specify the name of the morsel you created in the Template Morsels control panel module area.

{exp:template_morsels:fetch} 

Parameters

The following parameters are available for use:

name=

name="some_morsel" 

The 'name' parameter tells the model which template morsel to fetch. You create and name morsels in the Template Morsels CP.

site=

site="my_site" 

If you are using the Multi-site Manager for EE you can fetch morsels from any of your other sites by providing their names in the 'name' parameter and the appropriate site to which a morsel belongs in the 'site' parameter. Note that the site parameter accepts only one site name at a time. By default, Template Morsels will assume the morsel is from the current site.

Dynamic Data

The Fetch tag has the ability to pass data from your template to your morsel dynamically. If you provide more parameters than the simple name and site parameters you will switch the Template Morsels module into dynamic mode. This will create a copy of a normal morsel and cache it to the database. The copy will receive as variables the parameters that you passed across. This way you can have dynamic versions of the normal template morsel you created. For example, you can use this method to create morsels that respect the url title of a page or the category designator.

Dynamic morsels are refreshed using the same rules as the parent morsel to which they are attached. However, since they are dynamic, these morsels are marked to be refreshed rather than being refreshed at the same time as their parent. Since morsels are dependent on the context of the page, they are only refreshed if they are flagged for refresh and if their page is loaded.

Remember, you must create a morsel in the CP before you call it in a template. As such, you should plan which variables you intend to pass through your parameters and call these in the definition of your morsel in the CP. For example, if a morsel is going to be dynamic based on a URL title you would first create the morsel in the CP, placing the {url_title} variable where you need it in your morsel. Then when you call the morsel in a template, pass the page's URL title across as a parameter like this url_title="{segment_3}".

Your morsel code in CP:

<div class="{url_title}">Something</div> 

Morsel fetch in template:

{exp:template_morsels:fetch name="morsel_name" url_title="{segment_3}"} 

Examples

The following is a basic example of how to pull a template morsel your created in the Template Morsels CP (assuming the name of the morsel is recent_channel_entries):

Your morsel code in CP:

<ul>
{exp:channel:entries channel="articles" limit="5"}
    <li><a href="{title_permalink="news/article"}">{title}</a></li>
{/exp:channel:entries}
</ul>

Morsel fetch in template:

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