Backend Templating Engines - Vincentvanleeuwen/project-tech-2020 GitHub Wiki

There are a lot of templating engines. You've got EJS, Handlebars, Jade. Theres just too many to note down. Each templating engine has it's own features. Let's look at these three templates.

EJS

EJS uses the extension .ejs. If you want to loop over your database and place an element for each data in the database you can use:

<% database.forEach(function(data){ %>
    // Here you can tell EJS to use a template file for each data in database.
    <%- include('user/show', {data: data}); %>
  <% }); %>

As you can see you can use javascript in your templating files with EJS.

Jade

Jade uses a very different kind of templating style. In jade you could do

each data in database
// for every data, make an li with the data
li=data

Handlebars

Handlebars uses {{}} to define a dynamic value. For instance

{{# each database}}
// Here you can create a partial, for each data in database. You send the data by calling name:name.
  {{> customtemplate
    name: name
  }}
{{/ each }}

Conclusion

Because I've worked with frameworks, I'm kind of used to the curly brackets. Hence why I went for Handlebars. I felt like handlebars could help me feel the most secure in my code. Because the <% from EJS gives me PHP vibes, which I very much dislike. Jade uses almost nothing which makes the code harder to understand. That's why if felt like Handlebars is the best fit for me.

Creative Bloq Staff, (2013, September 12), "The top 5 JavaScript templating engines", [article] from: https://www.creativebloq.com/web-design/templating-engines-9134396

EJS, (2020, June 3), "Install", [documentation] from: https://ejs.co/#install Jade, (2020, June 3), [documentation] from: http://jade-lang.com/ Handlebars, (2020, May 25), "Guide", [documentation] from: https://handlebarsjs.com/guide/

⚠️ **GitHub.com Fallback** ⚠️