DRY Template Layouts and Partials

In this video, we will convert our one file templates to make use of ExpressionEngine’s template layouts and partials

In this video, we will convert our one file templates to make use of ExpressionEngine’s template layouts and partials

What We Do

  • Create our first Template Layout
  • Use Layout Variables
  • Create Template partials

Code Snippets

Basic Template Layout Example

{!-- Our Layout--}
<!DOCTYPE html>
<html>
<head>
    <title>My Site</title>
</head>
<body>
    {layout:contents}
</body>
</html>


{!-- Our code --}
{layout="template_group/template"}

<p>Hello world!</p>

Template Layout With Template Variables

{!-- Our Layout--}
<!DOCTYPE html>
<html>
<head>
    <title>{layout:title}</title>
</head>
<body>
    {layout:contents}
</body>
</html>


{!-- Our code --}
{layout="template_group/template"}

{layout:set name="title"}This title will show up now!{/layout:set}

<p>Hello world!</p>

Links

  • ExpressionEngine Template Layouts: https://docs.expressionengine.com/latest/templates/layouts.html#template-layouts
  • ExpressionEngine Template Layout Variables: https://docs.expressionengine.com/latest/templates/layouts.html#layout-variables
  • ExpressionEngine Template Partials: https://docs.expressionengine.com/latest/templates/partials.html
  • See all of the site build in action in the Learn EE git repository.

Take It For A Test Drive

Get a free scan and start your trial today!

Additional Resources

Ready to dive in?
Start your free 15 day trial today.

Sign Up For Updates

We'll keep you in the loop of new features, resources, and articles!
We keep your info private.

© 2021 tripleNERDscore. All rights reserved.