Posted by: R Manimaran | December 9, 2014

SharePoint 2013: Using Handlebarjs in SharePoint- Part 2

In the part1 we have seen how to create a Handlebarjs template and merge our REST API output with that template. In that output the date time values of Created and Modified is not well formatted. Below is the un-formatted output.


In this we will use Moment.js to do formatting.


  • js help us to parse, validate, manipulate and display dates in the JavaScript.
  • It’s having rich set of methods to format the date string.
  • You can download the moment.js from here

In the Handlebars we can create our custom methods to do additional functionality. Using the RegisterHelper we can create our custom method. Let’s create a method named “FormatDate” which will accept a parameter.

Handlebars.registerHelper("FormatDate", function (date) {

return moment(date.toString()).format('LL');



Some of the Moment.js Format strings;


To Call the Format Date function we need to change the HandleBars Template we have designed. Below is the updated template.

<script id="employees-template" type="text/x-handlebars-template">



<th>Employee Name</th>














<td>{{FormatDate Created}}</td>

<td>{{FormatDate Modified}}</td>





Now the output of my page will be like below.



  1. […] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: