Note that there are some explanatory texts on larger screens.

plurals
  1. POExpressjs + handlebars formatting date
    primarykey
    data
    text
    <p>i've got this object</p> <pre><code>{ title: 'A TITLE', description: 'Lorem Ipsum...', _id: 50806930bbf612a858000013, __v: 0, screenings: [ { venue: 'Venue1', dates: [Object] }, { venue: 'Venue2', dates: [Object] } ] } </code></pre> <p>coming out of my mongoDB.</p> <p><code>dates</code> is a list of dates (dah!).</p> <p>My issue is now I want to have them formatted with momentjs <strong>server-side</strong>.</p> <p>It would look like I should be using mustache lambdas, but it appears impossible using my stack (<strong>expressjs</strong>, <strong>consolidate</strong>, <strong>handlebars</strong>...)</p> <p>Anybody solved this?</p> <p>Here's what I'm trying now</p> <pre><code>Theatre.find({"screenings.dates":{$gte:lastSunday, $lte:nextSunday}}, function(err, entities){ res.render('index', { entities: entities, giveitatry: function(a) { return moment(a).format("MMM Do YY") } }); }); </code></pre> <p>and on my template I have:</p> <pre><code>{{#entities}} &lt;div class="span3"&gt;{{#giveitatry}} {{dates.0.}} {{/giveitatry}}&lt;/div&gt; {{/entities}} </code></pre> <p>Here's part of the expressjs conf</p> <pre><code>var moment = require('moment'); var express = require('express') , cons = require('consolidate') , name = 'mustache'; app.configure(function(){ app.set('view engine', 'hjs'); app.engine('.hjs', cons.mustache); ... </code></pre> <p>yes, extension's still hjs 'cause i started using hogan but i wasn't able to do it with hogan so i moved to consolidate+mustache.</p> <p>i'm using node v0.8.8 and expressjs 3.0.0rc4</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload