问题描述:

I have a route in which I want to render a handlebars view using non default layout and also pass some JSON data to the template as well.

I have tried the following two variations, the layout does get changed but the context variable is not being passed properly to the template.

res.render('study-feed', {layout: viewConfig.unauthenticatedLayout, locals: context})

res.render('study-feed', {layout: viewConfig.unauthenticatedLayout, data: context})

However , if you I pass the data without changing layout like the following, it gets passed and is accessible by the handlebars.

res.render('study-feed', context)

Update:

The 'study-feed' handlebars tamplate is as following:

{{#section 'head'}}

{{#withFirst studyFeed.posts}}

<title>{{this.material.name}} | DrBeen</title>

<meta name="description" content="{{this.material.description}}">

{{/withFirst}}

{{/section}}

And considering it I used the following way to render the template but it also did not work.

res.render('study-feed', {layout: viewConfig.unauthenticatedLayout, studyFeed: context})

相关阅读:
Top