Archive | templating

RSS feed for this section

HTML Templates via JavaScript Template Literals

You know those super cool backticks-for-strings in new JavaScript?

let emotion = `happy`;
let sentence = `Chris is feeling ${emotion}`;

Besides the variable interpolation in there being mighty handy, the do multi-line strings wonderfully, making them great for chunks of HTML:

const some_html = `
<div class="module>
<h2>${data.title}</h2>
<p>${data.content}</p>
</div>
`;

That doesn’t look overly different than JSX does it?! Maybe we’d do something like that as a React component:

class MyModule extends React.Component {
render() {
return
<div class="module">


HTML Templates via JavaScript Template Literals is a post from CSS-Tricks

Four Killer Features of Nunjucks

Nunjucks calls itself “A rich and powerful templating language for JavaScript”, which sounds about right. It’s not intentionally super lightweight like Mustache or the slightly more robust (but still pretty light) Handlebars. It’s a full-on language, packed with all kinds of stuff you might want when writing templates.

You can run it in the browser, but you probably shouldn’t. This is meant to be run in Node.js and used to compile templates server side.

In other words: it’s a …


Four Killer Features of Nunjucks is a post from CSS-Tricks