{"id":19736,"date":"2019-04-09T21:19:22","date_gmt":"2019-04-09T13:19:22","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=19736"},"modified":"2025-04-24T17:14:24","modified_gmt":"2025-04-24T09:14:24","slug":"a-look-into-handlebarsjs","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/","title":{"rendered":"Beginner&#8217;s Guide to Using Handlebars.js"},"content":{"rendered":"<p>In this post, we are going to look into <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/handlebarsjs.com\/\">Handlebars<\/a>, a JavaScript templating engine based on <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/mustache.github.io\/\">Mustache<\/a>. It shares the same functionalities with Mustache but sports several new features. Handlebars is a handy templating tool, particularly for <strong>displaying data series in JSON format<\/strong>, which today is a common data-formatting form used in web application APIs. Check out this <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.microsoft.com\/en-gb\/\">introductory post<\/a>, which explains JSON really well.<\/p>\n<p>In this article, we are going to walk you through some of Handlebars\u2019 basic functionalities, and we will also work on a real example at the end. If this is something you want to get to know, then let\u2019s get started.<\/p>\n<h2>Getting Started<\/h2>\n<p>To start off, let\u2019s go to the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/handlebarsjs.com\/\">Handlebars<\/a> website and download the source code file, <code>handlebars.js<\/code>. Put the file in an appropriate folder within your project. Link the file from your HTML documents. You can add the link inside the <code>&lt;head&gt;<\/code> tag or before the closing <code>&lt;\/body&gt;<\/code> tag.<\/p>\n<pre>\n  &lt;script src=\"js\/handlebars.js\"&gt;&lt;\/script&gt;\n<\/pre>\n<p>Alternatively, you can also link to the Handlebars source from a CDN.<\/p>\n<pre>\n  &lt;script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/handlebars.js\/1.3.0\/handlebars.js\"&gt;&lt;\/script&gt;\n<\/pre>\n<p>Once that\u2019s done, we can start creating a template.<\/p>\n<h2>Basic Template<\/h2>\n<p>Let\u2019s add our data: a name, age, and where the person comes from.<\/p>\n<pre>\n  var dataSource = {\n    \"name\": \"Joe Bloggs\",\n    \"age\": \"19\",\n    \"from\": \"United Kingdom\"\n  }\n<\/pre>\n<p>This data serves as an example. As mentioned, you can retrieve similar forms of data from most web applications that provide an open API, such as <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/dev.twitter.com\/\">Twitter<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developers.facebook.com\/docs\/instagram\">Instagram<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.flickr.com\/services\/api\/\">Flickr<\/a>, and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/dribbble.com\/api\">Dribbble<\/a> \u2013 though you\u2019ll likely get more lines of data than shown above. Alternatively, you can try <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/json-generator.com\/\">JSON Generator<\/a> to generate some random data.<\/p>\n<h2>The Template<\/h2>\n<p>Once we have the data, we can create the template to place these data. Let\u2019s look at the following code.<\/p>\n<pre>\n  &lt;div id=\"content\" class=\"content-wrap\"&gt;\n    &lt;script id=\"template\" type=\"text\/x-handlebars-template\"&gt;\n      &lt;p&gt;Hi, I'm {{name}}. I'm {{age}}, and I'm from {{from}}&lt;\/p&gt;\n    &lt;\/script&gt;\n  &lt;\/div&gt;\n<\/pre>\n<p>A Handlebars template is set within a <code>&lt;script&gt;<\/code> tag with a special type: <code>text\/x-handlebars-template<\/code>, and preferably also with an ID, because selecting <strong>an element<\/strong> by <em>ID<\/em> in JavaScript is technically more straightforward and faster than using a <em>class<\/em>.<\/p>\n<p>Each piece of data is declared within double curly braces, <code>{{...}}<\/code>; this is also known as a <strong>Handlebars expression<\/strong>.<\/p>\n<p>However, before we can see the result in the browser, we have to <em>compile<\/em> these codes, merging the data into the template.<\/p>\n<h2>Compiling<\/h2>\n<p>Let\u2019s store the template in a JavaScript variable, like so.<\/p>\n<pre>\n  var template = $('#template').html();\n<\/pre>\n<p>We then pass the <code>template<\/code> variable into <code>Handlebars.compile()<\/code> to compile the template.<\/p>\n<pre>\n  var compile = Handlebars.compile(template);\n<\/pre>\n<p>The most important part of the above code is the variable\u2019s name, <code>compile<\/code>. We will use it along with our data to generate the final result, like so:<\/p>\n<pre>\n  var result = compile(dataSource);\n<\/pre>\n<p>Lastly, we put it into the <code>#content<\/code> element using the jQuery <code>.html()<\/code> method this way.<\/p>\n<pre>\n  $('#content').html(result);\n<\/pre>\n<p>This will give us the following result in the browser:<\/p>\n<p><figure><img decoding=\"async\" alt=\"Handlebars basic output example\" src=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg\"><\/figure>\n<\/p>\n<h2>HTML Escaping<\/h2>\n<p>Sometimes our data might contain HTML tags, for example:<\/p>\n<pre>\n  var dataSource = {\n    \"name\": \"&lt;em&gt;Joe Bloggs&lt;\/em&gt;\",\n    \"age\": \"19\",\n    \"from\": \"United Kingdom\"\n  }\n<\/pre>\n<p>By default, Handlebars will escape these tags. It will turn the tags into their HTML entities: <code>&lt;<\/code> becomes <code>&lt;<\/code> and <code>&gt;<\/code> becomes <code>&gt;<\/code>. This will result in an unexpected output in the browser, as shown below:<\/p>\n<p><figure><img decoding=\"async\" alt=\"Handlebars HTML escaped output\" src=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/html-escape.jpg\"><\/figure>\n<\/p>\n<p>To prevent Handlebars from converting HTML tags into entities and instead treat them as actual HTML, use triple curly braces <code>{{{...}}}<\/code> to declare the data, like so:<\/p>\n<pre>\n  Hi, My name is {{{name}}}. ...\n<\/pre>\n<p>There you go! The heading tag is now rendered correctly, and the name is displayed in italics.<\/p>\n<p><figure><img decoding=\"async\" alt=\"Handlebars HTML unescaped output\" src=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/html-unescape.jpg\"><\/figure>\n<\/p>\n<h2>Conditional Helper<\/h2>\n<p>Handlebars supports <em>conditional helpers<\/em> (also known as conditional functions). This feature is an exclusive addition to Handlebars, not available in Mustache. A <em>conditional helper<\/em> is useful for preventing data rendering if the value is empty. As an example, let\u2019s remove the value from our <code>age<\/code> data.<\/p>\n<pre>\n  var dataSource = {\n    \"name\": \"Joe Bloggs\",\n    \"age\": \"\",\n    \"from\": \"United Kingdom\"\n  }\n<\/pre>\n<p>We use the conditional helper like this. Since the age value is not present, the line `I\u2019m {{age}},` will not be displayed.<\/p>\n<pre>\n  {{#if age}}I'm {{age}},{{\/if}}\n<\/pre>\n<p>In the browser, the line mentioned above will not be rendered.<\/p>\n<p><figure><img decoding=\"async\" alt=\"Handlebars conditional helper output\" src=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/empty-value.jpg\"><\/figure>\n<\/p>\n<p>Additionally, Handlebars will treat the data as empty if the value is explicitly set to <code>undefined<\/code> or <code>false<\/code>.<\/p>\n<h2>Loop<\/h2>\n<p>Handlebars also supports loops. As in other programming languages, loops are used to iterate over a series of objects. Currently, we only have one object containing three lines of data. Let\u2019s extend our example with two more objects, like so:<\/p>\n<pre>\n  var data = [{\n    \"name\" : \"Joe Bloggs\",\n    \"age\"  : \"19\",\n    \"from\" : \"United Kingdom\"\n  }, {\n    \"name\" : \"Jane Doe\",\n    \"age\"  : \"21\",\n    \"from\" : \"United State\"\n  }, {\n    \"name\" : \"John Doe\",\n    \"age\"  : \"20\",\n    \"from\" : \"United Nation\"\n  }];\n<\/pre>\n<p>Since we now have more than one object, our current template will no longer work to render these data correctly. In this case, we must use the Handlebars loop, wrapping our template within <code>{{#each}} ... {{\/each}}<\/code>. We may also need to change the template structure.<\/p>\n<p>In this example, we will display these data in a list.<\/p>\n<pre>\n  &lt;script id=\"template\" type=\"text\/x-handlebars-template\"&gt;\n    &lt;ul&gt;\n      {{#each this}}\n        &lt;li&gt;Hi, My name is {{{name}}}. {{#if age}}I'm {{age}},{{\/if}} and I'm from {{from}}&lt;\/li&gt;\n      {{\/each}}\n    &lt;\/ul&gt;\n  &lt;\/script&gt;\n<\/pre>\n<p>Here is the result that we will see in the browser:<\/p>\n<p><figure><img decoding=\"async\" alt=\"Handlebars loop helper output\" src=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/loop.jpg\"><\/figure>\n<\/p>\n<h2>Example<\/h2>\n<p>Now let\u2019s implement this in a real example. This time, we want to display a profile from Forrst, a hub for designers and developers. Forrst provides a simple method to retrieve data. In our case, we can use <code>https:\/\/forrst.com\/api\/v2\/users\/info?username={username}<\/code> to retrieve a user profile. We will get data similar to this (Note: the actual data is very long, so I have truncated it):<\/p>\n<pre>\n  var forrstProfile = {\n    \"id\": 24606,\n    \"username\": \"jimmyliu\",\n    \"name\": \"Jimmy Liu\",\n    \"url\": \"http:\\\/\\\/forrst.com\\\/people\\\/jimmyliu\",\n    \"likes\": \"11\",\n    \"followers\": \"10\",\n    \"following\": \"2\",\n    \"photos\": {\n      \"medium_url\": \"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3151a9294608c3143551aa265f00bf71.jpg?s=75&d=https:\\\/\\\/forrst.com\\\/assets\\\/images\\\/default_75.jpg\",\n      \"small_url\": \"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3151a9294608c3143551aa265f00bf71.jpg?s=45&d=https:\\\/\\\/forrst.com\\\/assets\\\/images\\\/default_45.jpg\",\n      \"thumb_url\": \"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3151a9294608c3143551aa265f00bf71.jpg?s=25&d=https:\\\/\\\/forrst.com\\\/assets\\\/images\\\/default_25.jpg\"\n    },\n    \"bio\": \"&lt;p&gt;A graphic and web designer based in Cupertino, California. Follow me on Twitter &lt;a href=\\\"http:\\\/\\\/twitter.com\\\/jimmyliu\\\"&gt;&lt;\\\/a&gt;&lt;a href=\\\"\\\/people\\\/jimmyliu\\\"&gt;@jimmyliu&lt;\\\/a&gt;&lt;\\\/p&gt;\\\\n\",\n    \"is_a\": \"developer & designer\"\n  };\n<\/pre>\n<p>We will put this data into the following template:<\/p>\n<pre>\n  &lt;div id=\"forrst\" class=\"forrst-profile\"&gt;\n    &lt;script id=\"forrst-profile-template\" type=\"text\/x-handlebars-template\"&gt;\n      &lt;div class=\"profile\"&gt;\n        &lt;figure class=\"avatar\"&gt;\n          &lt;img src=\"{{photos.medium_url}}\" alt=\"\"&gt;\n        &lt;\/figure&gt;\n        &lt;div class=\"person\"&gt;\n          &lt;h4 class=\"person-name\"&gt;&lt;a href=\"{{url}}\"&gt;{{name}}&lt;\/a&gt;&lt;\/h4&gt;\n          &lt;div class=\"person-bio\"&gt;{{{bio}}}&lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n      &lt;div class=\"social-count\"&gt;\n        &lt;div class=\"social-item social-posts\"&gt;\n          &lt;div class=\"heading\"&gt;Posts&lt;\/div&gt;\n          &lt;div class=\"counts\"&gt;{{posts}}&lt;\/div&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"social-item social-followers\"&gt;\n          &lt;div class=\"heading\"&gt;Followers&lt;\/div&gt;\n          &lt;div class=\"counts\"&gt;{{followers}}&lt;\/div&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"social-item social-following\"&gt;\n          &lt;div class=\"heading\"&gt;Following&lt;\/div&gt;\n          &lt;div class=\"counts\"&gt;{{following}}&lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n    &lt;\/script&gt;\n  &lt;\/div&gt;\n<\/pre>\n<p>Let\u2019s compile them together, like so:<\/p>\n<pre>\n  var template = $('#forrst-profile-template').html();\n  var compile  = Handlebars.compile(template);\n  var result   = compile(forrstProfile);\n  $('#forrst').html(result);\n<\/pre>\n<p>With a couple of lines of CSS, we can achieve a nicer result.<\/p>\n<p>You can download the source and see the demo from these links:<\/p>\n<div class=\"button\">\n    <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hongkiat.github.io\/handlebars-template\/\">View Demo<\/a>\n    <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/hongkiat\/handlebars-template\/\">Download Source<\/a>\n<\/div>\n<h2>Final Thought<\/h2>\n<p>I previously used jQuery for templating, which I think was the wrong approach, as my code turned out messy. When dealing with a large chunk of data, it is far better and neater to use Handlebars for templating and displaying it. I hope this serves as a good reference for you to get started with Handlebars.<\/p>","protected":false},"excerpt":{"rendered":"<p>In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but sports several new features. Handlebars is a handy templating tool, particularly for displaying data series in JSON format, which today is a common data-formatting form used in web application APIs.&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[352],"tags":[4117],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Beginner&#039;s Guide to Using Handlebars.js - Hongkiat<\/title>\n<meta name=\"description\" content=\"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Beginner&#039;s Guide to Using Handlebars.js\" \/>\n<meta property=\"og:description\" content=\"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-09T13:19:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T09:14:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"Beginner&#8217;s Guide to Using Handlebars.js\",\"datePublished\":\"2019-04-09T13:19:22+00:00\",\"dateModified\":\"2025-04-24T09:14:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/\"},\"wordCount\":883,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/a-look-into-handlebarsjs\\\/result.jpg\",\"keywords\":[\"Javascripts\"],\"articleSection\":[\"Web Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/\",\"name\":\"Beginner's Guide to Using Handlebars.js - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/a-look-into-handlebarsjs\\\/result.jpg\",\"datePublished\":\"2019-04-09T13:19:22+00:00\",\"dateModified\":\"2025-04-24T09:14:24+00:00\",\"description\":\"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/a-look-into-handlebarsjs\\\/result.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/a-look-into-handlebarsjs\\\/result.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/a-look-into-handlebarsjs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Beginner&#8217;s Guide to Using Handlebars.js\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Beginner's Guide to Using Handlebars.js - Hongkiat","description":"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/","og_locale":"en_US","og_type":"article","og_title":"Beginner's Guide to Using Handlebars.js","og_description":"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but","og_url":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2019-04-09T13:19:22+00:00","article_modified_time":"2025-04-24T09:14:24+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"Beginner&#8217;s Guide to Using Handlebars.js","datePublished":"2019-04-09T13:19:22+00:00","dateModified":"2025-04-24T09:14:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/"},"wordCount":883,"commentCount":2,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg","keywords":["Javascripts"],"articleSection":["Web Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/","url":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/","name":"Beginner's Guide to Using Handlebars.js - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg","datePublished":"2019-04-09T13:19:22+00:00","dateModified":"2025-04-24T09:14:24+00:00","description":"In this post, we are going to look into Handlebars, a JavaScript templating engine based on Mustache. It shares the same functionalities with Mustache but","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/a-look-into-handlebarsjs\/result.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/a-look-into-handlebarsjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Beginner&#8217;s Guide to Using Handlebars.js"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-58k","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=19736"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19736\/revisions"}],"predecessor-version":[{"id":74108,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19736\/revisions\/74108"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=19736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=19736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=19736"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=19736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}