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
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
Comments 0
Be the first to comment!