У меня есть небольшое приложение hapijs, и я хочу отображать цитаты в формате json из вспомогательного модуля, но не могу его отобразить.
index.js:
server.views({
engines: {
html: require('handlebars')
},
context: defaultContext,
relativeTo: __dirname,
path: './views',
layoutPath: './views/layout',
helpersPath: './views/helpers',
partialsPath: './views/partials',
layout: false,
isCached: false
});
server.route({
method: 'GET',
path: '/quotes',
handler: function (request, reply) {
reply.view('quotes');
}
});
цитаты.html:
<h1>Word of the day by {{{ quotes }}}</h1>
{{{quotes}}}
цитаты.js:
module.exports = function () {
var quotes = [
{ author: "Kobayashi Issa", text: "What a strange thing!<br>to be alive<br>beneath cherry blossoms." },
{ author: "Kobayashi Issa", text: "Summer night--<br>even the stars<br>are whispering to each other." },
{ author: "Kobayashi Issa", text: "Never forget:<br>we walk on hell,<br>gazing at flowers." },
{ author: "Kobayashi Issa", text: "Here<br>I'm here-<br>the snow falling." }
];
var id = Math.floor(Math.random() * quotes.length);
return quotes[id].text;
};
Если я возвращаю кавычки [id], я получаю «Слово дня от [object Object]» в браузере. Если я изменю html руля на {{{ quotes.author }}}, он будет пустым. Есть ли что-то в hapijs, требующее настройки руля?
Я пытался сделать {{#each quotes}} ... {{/each}}, но это не зацикливается. Если я верну JSON.stringify(quotes[id]); Я получаю Слово дня от {"author":"Кобаяши Иссы","text":"Какая странность! Быть живым под цветущей вишней."}
Я знаю, что кавычки вызываются дважды.
привет Клаус