Tips and tricks


The Framework’s DRY (don’t repeat yourself) philosophy is the driving principle behind the template system. Advanced template inheritance features allow you to truly take DRY to its limits.

Extending blocks

If you need to include the parent block’s HTML in you current block, just use {% insert %} or {% parentblock %} (docs).

[todo: add example]

Creating dynamic menus with DRY

One of the challenges with DRY is creating dynamic menus where each menu is active depending on the currently displayed template. Since this requires a change within the HTML markup, this can be a bit complex. Here’s an example:

<!-- Home template-->
  <a class='active'>Home</a>
  <a href='/comminuty'>Community</a>
  <a href='/about'>About</a> ...
  
<!-- Community template-->
  <a href='/home'>Home</a>
  <a class='active'>Community</a>
  <a href='/about'>About</a> ...

<!-- About template-->
  <a href='/home'>Home</a>
  <a href='/community'>Community</a>
  <a class='active'>About</a>

Because the active class is applied to a different link each time, this template is difficult to extend. You can however use a clever combination of template variables and block extensions to create an elegant DRY solution:

Recursive template insertions

When you have hierarchical lists (such as nested categories) it can be useful to recursively include (or insert as it is called in OFW) a template. Here’s an example of how to do it:

Outlast Web & Mobile Development (c) 2023 | Privacy Policy |