mustache-layout-s
Package for mustache-express that enables to build Layouts (extends) views.
Problem
If you use mustache-express you can include/import views (partials), but you can't extend your view, by extend i mean 'inherit'.
You have a solution to this problem: https://stackoverflow.com/questions/7925931/can-mustache-templates-do-template-extension, but mustache-layout package suggest an alternative solution.
Use case
If you don't want to copy/paste the header/footer, or maybe an menu bar that is repeated in all admin sub sections,
each time you render a page/view, you just need to use the function: build
Install
npm i mustache-layout-s
How to use it with example
In your server.js file of express app, add the app instance to our package.
Mustache-express package implementation is also explained.
const mustacheExpress = ;const mustacheLayout = ; const app = ; // set template engine mustache-expressapp;app;app; mustacheLayout;
Controller
Put all the layer in the buildLayout function as parameters,
warning:
- you need to respect order, from the smallest layout to the bigger (base.html)
- data properties should be named as in the view
const layout = ; router;
View
warning You need to use the keyword
child
in layout view pages. don't forget triple braces {{{ }}}
Use your passed data here
<!-- ditor.view.html --> {{ user }}
<!-- admin.view.html --> Admin section layout {{{ child }}}
<!-- base.view.html --> {{ > layout/header.view }} {{{ child }}} {{ > layout/footer.view }}