I do this by passing blocks of template content via layout variables
. Thus you can put template specific content elements into a layout, but don't need to worry about doing any logic switching within the layout itself.
Here is an example:
First - here is the code within the layout to insert whatever is in a template design content block called page_specific_js_and_views
:
{if layout:page_specific_js_and_views}{layout:page_specific_js_and_views}{/if}
The logic tests to see if a layout variable has been set, and if it has been, simply includes it within the layout.
Now, here is the code that appears within one of the templates that uses this layout - it inserts some specific javascript to load into the layout just for this template:
{layout:set name="page_specific_js_and_views"}
<!-- Specific Page Vendor and Views -->
<script src="/themes/site_themes/vendor/revolution/js/jquery.themepunch.tools.min.js" async></script>
<script src="/themes/site_themes/vendor/revolution/js/jquery.themepunch.revolution.min.js"></script>
<script src="/themes/site_themes/js/home-revolution-slider-init.min.js"</script>
{/layout:set}
When this page is rendered onscreen it gets the slider code added. When other templates use this layout they don't.
If you use nested layouts (a really good idea) you can extend this idea by simply 'passing' the template specific content down the layout chain using simple formats like this:
{layout:set name="page_specific_js_and_views"}
{layout:page_specific_js_and_views}
{/layout:set}
This structure simply looks to see if a layout variable of particular type has been set by a template, and if it has, passes it on to the next layout in the chain by setting a new layout variable with the same name.
Hope this makes sense... if not do clarify your question.