使用ハンドル4.0.6および7.4.0 NodeJS、出力I出力私のテンプレートが{{this}}
を使用して受信されたデータ、ただしハンドルバーは値を返さないが、それはに存在する{{}}この
{ _id: 58a7de1c7275f8208438ae4a,
author: 589a12b5a08e0c2f24ece4e8,
dateCreated: 2017-02-18T05:39:40.650Z,
section: 58a7d57c9ce34527bce7e041,
slug: 'this-one-will-work',
title: 'this one will work',
color: '#d313ff',
__v: 0,
fields:
[ { fieldId: 58a3cff51da0ea5d00972804,
fieldSlug: 'color',
value: '#d313ff',
_id: 58a7de1c7275f8208438ae4b } ] }
のすぐ下のテンプレートに{{color}}
または{{this.color}}
を使用しても何も出力されません。
プロミスでmongooseを使ってデータを取得してから、それをコンパイルして、res.send()
を使用しています。ここで
は私のコンパイル機能です:
const Handlebars = require('handlebars');
const fs = require('fs');
const path = require('path');
module.exports = (template, data) =>
new Promise((resolve, reject) => {
const templateWithFormat = template.endsWith('.hbs') ? template : `${template}.hbs`;
const templatePath = path.resolve(__dirname, '..', '..', 'templates', templateWithFormat);
fs.readFile(templatePath, 'utf-8', (err, file) => {
if (err) reject(err);
const compiled = Handlebars.compile(file);
const html = compiled(data);
resolve(html);
});
});
誰もが任意のアイデアがありますか?
ありがとうございます!
私はこのコードを実行しようとしました:http://jsbin.com/goxufawulo/1/edit?jsそしてそれは '#d313ff'として色をレンダリングします。 Node.js 6.9とハンドルバー4.0.6を使用します。 望ましい出力が得られるコードの実行可能なチャンクを提供できますか? –
私はノード7.4.0とハンドルバー4.0.6を使用しています。私は実際にあなたのJSBinにない多くのことをやっていないので、ちょうどノードのバージョンですか?私はチャンスを得るときに別のバージョンでそれを試してみます。ノード7.4.0でテストされたばかりの – jasonetco
。違う何かが原因です。 –