Set template

This is the template in Set. Unlike the Handlebars example, the template looks almost identical to the final render and can be used to design in the browser. You can even add dummy data (like the second and third list items) which are not included in the final render. Unlike the Plates example, no mapping code is necessary. Data is mapped automatically to the HTML elements.

A placeholder title

Hello from name of the templating engine!

This paragraph is a placeholder.

This should link to Aral’s homepage.

This should link to

This should be Aral’s headshot:

Friends and their skills

  • Name knows skills.

  • Some sample content.

  • That could help when styling the page.

No friends found.


<h1 data-set-text='title'>A placeholder title</h1>

<p>Hello from <span data-set-text='name'>name of the templating engine</span>!<p>

<!-- Text substitution -->
<p data-set-text='content'>This paragraph is a placeholder.</p>

<!-- Attribute substitution -->
<p><a data-set-attribute='href newURL' href='/'>This should link to Aral’s homepage.</a></p>

<!-- Custom Formatter -->
<p><a data-set-attribute='href correctURLFragment fullURL' href=''>This should link to</a></p>

<p>This should be Aral’s headshot:</p>

<!-- Placeholder image -->
<img data-set-attribute='src aralImageURL' src=''>

<h2>Friends and their skills</h2>

<!-- Conditional -->
<ul data-set-if='friends'>
  <!-- Repeater -->
  <li data-set-repeat='friend friends'>
    <p><span data-set-text=''>Name</span> knows <span data-set-text='friend.skills'>skills</span>.</p>

  <!-- Dummy data -->
  <li data-set-dummy>
    <p>Some sample content.</p>
  <li data-set-dummy>
    <p>That could help when styling the page.</p>

<!-- Conditional -->
<p data-set-if='not:friends'>No friends found.</p>


data =
  title: 'Set sample'
  name: 'Set'
  content: 'This is a simple example to demonstrate Set, a templating engine for Express (node.js) and client‐side JavaScript.'
  newURL: ''
  correctURLFragment: 'ind'
  aralImageURL: ''
    {name: 'Laura', skills: 'design, development, illustration, speaking'},
    {name: 'Jo', skills: 'operations, cognitive psychology, sports coaching'},
    {name: 'Osky', skills: 'begging for food, looking cute, occasionally howling'}

Express 3 router (node.js)

exports.route = (request, response) ->
# Custom formatter
data.__set = {
    fullURL: (value) ->
      return 'http://' + value + '.com'
response.render 'simple', data