Template Morsels 1.x

Legacy documentation for Template Morsels 1.x.

The Template_Morsels:Escape tag allows you to escape parts of your Morsel's code to prevent it from being cached. This is useful when you have a large chunk of code you wish to cache but have a tag inside that you would like to keep "live".

{exp:template_morsels:escape} 
{exp:template_morsels:escape:pre} 

Examples

The following morsel code is an example of how you can escape code within a morsel. This code allows you to cache the product's title and description, while still allowing the availability of the product to always be fresh. Notice how the {entry_id} will be correctly parsed by the Channel Entries tag before the Query tag code is escaped:

{exp:channel:entries channel="products" limit="10"}
    <h3>{title}</h3>
    {product_description}
    {exp:template_morsels:escape}
        {exp:query sql="SELECT status as current_availability FROM exp_channel_titles WHERE entry_id = {entry_id}"}
            <span>Availability: {current_availability}</span>
        {/exp:query}
    {/exp:template_morsels:escape}
{/exp:channel:entries}

The following morsel code is an example of how you can pre-escape a code in a morsel. Pre-escaping means that the code between the {exp:template_morsels:escape:pre} tags is NOT parsed by the Template Morsel parser. It is pulled out before the morsel is parsed and put back after it is parsed. In other words, it is parsed by the Template parser after the {exp:template_morsels:fetch} tag puts it into the Template. This is useful if you have code that should only be parsed by the Template parser. A redirect, for instance.

{exp:channel:entries channel="products" limit="10"}
    <h3>{title}</h3>
    {product_description}
    {if no_results}
        {exp:template_morsels:escape:pre}
            {redirect="products/homepage"}
        {/exp:template_morsels:escape:pre}
    {/if}
{/exp:channel:entries}