how to convert

22 views
Skip to first unread message

来福王

unread,
Mar 2, 2016, 8:54:27 PM3/2/16
to Nunjucks
// in express route
res.locals.test = function ('fileId', callback) {
  return 'test(' + arg1 + ',' + String(callback) + ');'
}

res.render('index.html', {title: 'index'})

// in template index.html
{{ test('fileId', "function (M) {
    log('{{ title }}');
}") }}

how to convert  '{{title}}'  to 'index' in 'index.html'

Carl Meyer

unread,
Jun 10, 2016, 10:38:56 AM6/10/16
to Nunjucks

Remove both the string quotes and the var markers. Just use simply `title` instead of `'{{ title }}'`. You're already within a var context because of the outer curly braces, so you can just refer to vars by name to get their value; you never nest var markers in nunjucks. String quotes within a var context doesn't somehow take you back into a raw-template-data context.

Carl
Reply all
Reply to author
Forward
0 new messages