DADI has rebranded to Edge. Find out more.

Using the es6 Template Engine

The early releases of DADI Web relied on a single templating engine, but in Web 3.0 we introduced template engine support, giving the engineer a choice of templating languages.

The early releases of DADI Web relied on a single templating engine, DustJS. It’s powerful, lightweight, extendable, and has just the right amount of logic. But it’s not to everyone’s taste. So in Web 3.0 we introduced template engine support, giving the engineer a choice of templating languages and making it quick and easy for them to roll their own.

We recently built an RSS feed using DADI Web. This is arelatively straight forward task, so rather than using DustJS we decided to make use of the new ES6 engine.

Here’s a snippet of the item iterator:

${articles.results
  .map(i =>
    \`<item>
      <guid isPermaLink="false">${i.\_id}</guid>
      <title>${clean(i.title)}</title>
      <link>${i.url}</link>
      <pubDate>${utcDate(i.publicationDate)}</pubDate>
      <category>${clean(i.category.name)}</category>
      <category domain="${i.category.domain}">${clean(i.category.name)}</category>
   </item>\`
})

Just like DustJS, we have helpers. Small JS files that are called during render to mutate values. In this example I created two.

  1. clean which cleans html special characters, similar to PHP’s htmlspecialchars
  2. utcDate which converts an epoch timestamp into an RSS compatible utc date string

The total line count for the templates is just 37, with another 12 for the helpers.

Want to try it yourself? Read more about choosing an engine.

Related articles

More tutorials articles
Mail icon

Like what you are reading? Want to earn tokens by becoming an Edge Node? Save money on your hosting services? Build amazing digital products on top of Edge services? Join our mailing list.

To hear about our news, events, products and services, subscribe now. You can also indicate which services you are interested in, which we use for research and to inform the content that we send.

* You can unsubscribe at any time by emailing us at data@edge.network or by clicking on the unsubscribe link which can be found in our emails to you. Read our Privacy Policy.
Winner Best Edge Computing Platform Technology & Innovation Awards
Presented by Juniper Research