larvitviews

1.0.3 • Public • Published

Build Status Dependencies

Larvitviews

Templating wrapper for lodash templates, adding support for partials and hierarchy.

When we selected template driver we had the following requirements:

  1. All HTML should reside in the templates and nowhere else. This is not debatable.
  2. It should resemble HTML as much as possible. Especially since the front enders normally just know HTML/CSS/js. It should not be a totally "new" language. This issue have been a burden in the past for us, for example when we used XSLT.
  3. It should be fast. Really fast.

Used as the "view" part of the MVC micro framework larvitbase.

Usage

Template file /public/tmpl/test.tmpl:

<p>Hello <%= user %></p>

Javascript file:

const views = require('larvitviews')(),
      data  = {'user': 'Lilleman'};

console.log(views.render('test', data)); // <p>Hello Lilleman</p>

Full documentation on the upstream Lodash templates.

Template partials

Template file /public/tmpl/foo.tmpl:

<h1>Boo</h1>
<p><%= _.render('bar', obj) %></p>

Template file /public/tmpl/bar.tmpl:

Value is: <%= obj.value %>

And to render this write this javascript code:

const views = require('larvitviews');

console.log(views.render('foo', {'value': 'rev'}));
// Renders:
// <h1>Boo</h1>
// <p>Value is: rev</p>

Package Sidebar

Install

npm i larvitviews

Weekly Downloads

12

Version

1.0.3

License

MIT

Unpacked Size

7.47 kB

Total Files

8

Last publish

Collaborators

  • lilleman