node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

choo-layout

choo-layout is a way to wrap templates with other templates (yo dawg?)

The inspiration came from iron-router because I wanted to be able to have certain pages be contained within another without having to maintain each instance of the 'wrapper' template.


How to use it:

Create a layout:

const layout = require('choo-layout')
 
module.exports = layout`
      <div>
        <div class="row">here comes the train... :train:</div>
        <div>
          ${0}
        </div>
      </div>
      `

A layout can have multiple 'yields' (where the given page will go). Unfortunately there is no 'named' templates yet but it shouldn't be hard to add. (;))

Use a layout:

 
const layout = require('../views/layout')
const dashboard = require('../views/dashboard')
 
module.exports.boot = (app) => {
  app.router([
    ['/', layout(dashboard)]
  ])
 
  ...

Boom! You have a layout. If you wanted multiple templates in your layout, you would pass like you would pass an additional parameter to a function (because app.router doesn't need more arrays...)