What will you get from this article?
When you will finish to read this article, you'll know client-side templating and how to do this with Handlebars.js, and how it worths to give a try.
You will explore main features of Handlebars.js for better templating, like, built-in helpers/custom-helpers to add the logic in your template, partial for modularizing the code, and precompile the templates to increase the dom rendering speed and automation of precompiling process with Grunt.
When you will finish to read this article, you'll know client-side templating and how to do this with Handlebars.js, and how it worths to give a try.
You will explore main features of Handlebars.js for better templating, like, built-in helpers/custom-helpers to add the logic in your template, partial for modularizing the code, and precompile the templates to increase the dom rendering speed and automation of precompiling process with Grunt.
What’s client-side templating?
Before dive into the Handlbars.js, we need to understand what is client-side templating first. Every experience web developer might have some experience of writing JavaScript to generate HTML, something like,
After using templates on the projects, a person works on it does not need deep programming to make UI better, because template file is similar to HTML which is easy to modify via changing the tags, attributes and the position of tags.
Before dive into the Handlbars.js, we need to understand what is client-side templating first. Every experience web developer might have some experience of writing JavaScript to generate HTML, something like,
var person = {name:suman, age : 30} var elem = document.createElement('div'); elem.innerHTML = 'name=' + person.name + ' age=' + person.age result.appendchild(elem );
Now, think of above code as thousands line on the large and complex project, it would be error prone, sluggish, and hard to maintain. We need to separate those UI JavaScript codes with the tool which is easy to use, maintain, and flexible.
After using templates on the projects, a person works on it does not need deep programming to make UI better, because template file is similar to HTML which is easy to modify via changing the tags, attributes and the position of tags.
For example, above code can be written in Handlebars something like
name = {{ name }} age = {{age }}
So client-side templating is the tool to use the generate HTML using provided data with its own syntax. All we do this to separate the data and presentation code.
After using templates on the projects, a person works on it does not need deep programming to make UI better, because template file is similar to HTML which is easy to modify via changing the tags, attributes and the position of tags.
No comments:
Post a Comment