Sign In Register

How can we help you today?

Start a new topic
Answered

GSHTML handlebars date formatting

I'd like to format a date field in my search results. Handlebars doesn't support this natively and I can't find any documentation stating if Gamesparks provides any handlebars helpers or any way to make my own.


Do I have to loop over my objects in serverside JS and format the date fields? That's the only obvious way I'm seeing, but I'd like to be able to use a handlebars helper to do this. 


Best Answer
Hi Arnold
In your search results snippet you can format the date in the javascript/cloud code section.
For example

In javascript/cloud code section.

var players = [];
var results = playerCollection.find(query, {"displayName" : 1,"date":1}).limit(limit);
for ( var i in results)
{
   var myResults = results[i];
   var parseDate = parseInt(myResults.Date);
   var newDate = new Date(parseDate);
   var gmtDate = newDate.toGMTString();
   players.push({displayName:myResults.displayName,Date:gmtDate});
}
form.players = players;

}

In HTML / GSML section.

{{#each results.players}}
<hr/>
<gs-row>
<gs-col width="4">{{displayName}}</gs-col>
<gs-col width="4">{{Date}}</gs-col>
<gs-col width="1"><gs-link snippet="player_master?playerId={{_id.$oid}}" target="modal-large"><i class="icon-edit"/></gs-link></gs-col>
</gs-row>
{{/each}}

Thanks Katie

 

1 Comment

Answer
Hi Arnold
In your search results snippet you can format the date in the javascript/cloud code section.
For example

In javascript/cloud code section.

var players = [];
var results = playerCollection.find(query, {"displayName" : 1,"date":1}).limit(limit);
for ( var i in results)
{
   var myResults = results[i];
   var parseDate = parseInt(myResults.Date);
   var newDate = new Date(parseDate);
   var gmtDate = newDate.toGMTString();
   players.push({displayName:myResults.displayName,Date:gmtDate});
}
form.players = players;

}

In HTML / GSML section.

{{#each results.players}}
<hr/>
<gs-row>
<gs-col width="4">{{displayName}}</gs-col>
<gs-col width="4">{{Date}}</gs-col>
<gs-col width="1"><gs-link snippet="player_master?playerId={{_id.$oid}}" target="modal-large"><i class="icon-edit"/></gs-link></gs-col>
</gs-row>
{{/each}}

Thanks Katie

 

Login to post a comment