Layouts
Layouts are one of Eta's most convenient features -- along with partials, they allow you to separate your templates into clean and maintainable parts.
TL;DR
You can call
Inside your template. This will render the filepath
template with the current template body stored in it.body
. Your layout file will automatically have access to it
. it
can be overriden by passing data overrides:
More advanced
Eta defines a local function called layout
which stores a filepath (or template name) and parameters in inner template variables. Before a template returns, it checks to see whether the filepath is defined. If so, it returns the result of the following:
Alternatively, if includeFile
is not defined, it will fall back to include
:
Examples
Simple Layout
Conditional Layouts
One of the advantages of our layout function is that we can modify the layout as many times as we want. Eta just cares what it is set to by the time a template finishes rendering.
Of course, since Eta supports multi-line tag content, we could rewrite that as: