Skip to content

{exp:stash:not_found}

croxton edited this page Nov 26, 2014 · 16 revisions

Outputs the 404 template configured in Design > Templates > Global Preferences, with a 404 header and without changing the URL. An alternative to {redirect="404"} which can be problematic when used in embeds, capturing content with Stash, or with other third-party caching add-ons.

Simple example

{exp:channel:entries 
    channel="my_channel"
    require_entry="yes"
}
    {if no_results}
        {exp:stash:not_found}
    {/if}

{/exp:channel:entries}

Advanced example

ExpressionEngine only allocates the special {if no_results}..{/if} conditional to the outermost module tag in a template which contains nested tag pairs. Unfortunately this means the conditional doesn't work in nested tags.

To address this issue, Stash tags such as {exp:stash:cache} accept the unprefix="" parameter to effectively 'hide' the conditional from the template parser until the point you actually need to use it. The parameter should be used by the immediate parent tag of the tag where you want to use the conditional:

{exp:stash:cache unprefix="nested"}

    {stash:embed:views:layout}

    {exp:channel:entries 
        channel="my_channel"
        require_entry="yes"
    }
        {if nested:no_results}
            {exp:stash:not_found}
        {/if}

    {/exp:channel:entries}
{/exp:stash:cache} 
Clone this wiki locally