I'm having an odd issue with Stash and a 404 redirect. When an entry isn't found the "layout" template is getting rendered twice around the main Stash content. Anyone seen this before? I can kinda see why it is happening, but can see any way around it. Thoughts?
The page template
{!-- Layout --}
{embed="shared/_layout"}
{!-- Set main content --}
{exp:stash:set
name="main_content"
parse_tags="yes"
parse_depth="2"
no_results_prefix="nested"}
{exp:channel:entries limit="1" url_title="{segment_3}"}
{if nested:no_results}{redirect="404"}{/if}
{/exp:channel:entries}
{/exp:stash:set}
The 404 template
{!-- Layout --}
{embed="shared/_layout"}
{!-- Set main content --}
{exp:stash:set name="main_content"}
<h1>Page not found</h1>
{/exp:stash:set}
The layout template
<body>
HEADER GOES HERE!!!
{exp:stash:get name='main_content'}
FOOTER GOES HERE!!!
</body>
The resulting output to browser
<body>
HEADER GOES HERE!!!
<body>
HEADER GOES HERE!!!
<h1>Page not found</h1>
FOOTER GOES HERE!!!
</body>
FOOTER GOES HERE!!!
</body>
EDIT: Seems I can get around the issue by removing the Stash/layout stuff from the 404 template and just having it as...
<h1>Page not found</h1>
But then a 404 generated by some means other than no_results won't get the layout. Hmm. Ideas?