1

Good afternoon!

I’ve just “discovered” and started playing with layouts. So far, I love them!

But I have one question: Some of my pages, include custom stylesheets:

[code] [/code]

I can’t quite seem to figure out how to get this into the layout. If I try and use a normal variable in the main layout tag, the quotes (single / double) appear to mosh up the output.

I’ve also had zero success with the dynamic layout variables either:

[code] {layout:set name="color" value="red"} [/code]

Thoughts on how others include custom header info in their layouts….

  • I guess the question is how to conditionally-add template partials ("snippets") in layouts. – Jake Covert Apr 24 '16 at 23:41
1

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.

| improve this answer | |
  • This is perfect! Thanks so much. Not sure why I couldn't get the layout set variables to work for me earlier. – Jake Covert Apr 25 '16 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.