<title>车把变量{{page}}</title></head> 来自 panini 的 head title-tag 是来自 data.JSON 的对象的键
<title>Handlebars variable {{page}}</title></head> from panini in head tiile-tag is a key of the object from data.JSON
您好,我有 JSON 个文件:
{
"index" : "Main page",
"contacts" : "Find me!",
}
有一个车把模板可用于 panini(ZF):
<!doctype html>
<html lang="ru">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{#if page}}
<title>{{lookup data.this}}</title>
<link rel="stylesheet" href="assets/css/screen.css" />
{{/if}}
panini中的{{page}}是通过模板的页面名称(不带扩展名)。
而且我不知道如何编写正确的模板来通过键从数据对象中获取值。我想象它在解析 index.html panini 变量页面时具有值 "index"、contacts.html - "contacts" 并且 title-tag 中的魔法像这样工作 data.index.
在真实服务器上不会 运行。它应该只在本地计算机上工作,以帮助进行快速开发。
必须打开那个魔法的脚本:
//part of the gulpfile.js
gulp.task('pages', ['jade'], function() {
return gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest('dist'));
});
//part of the gulpfile.js
Lookup helper 语法如下:{{lookup data page}}
,如果你的 data.json 有这样的东西,它应该可以正常工作:
{
"index": "main page title",
"contact": "Contact page title"
}
您好,我有 JSON 个文件:
{
"index" : "Main page",
"contacts" : "Find me!",
}
有一个车把模板可用于 panini(ZF):
<!doctype html>
<html lang="ru">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{#if page}}
<title>{{lookup data.this}}</title>
<link rel="stylesheet" href="assets/css/screen.css" />
{{/if}}
panini中的{{page}}是通过模板的页面名称(不带扩展名)。 而且我不知道如何编写正确的模板来通过键从数据对象中获取值。我想象它在解析 index.html panini 变量页面时具有值 "index"、contacts.html - "contacts" 并且 title-tag 中的魔法像这样工作 data.index.
在真实服务器上不会 运行。它应该只在本地计算机上工作,以帮助进行快速开发。
必须打开那个魔法的脚本:
//part of the gulpfile.js
gulp.task('pages', ['jade'], function() {
return gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest('dist'));
});
//part of the gulpfile.js
Lookup helper 语法如下:{{lookup data page}}
,如果你的 data.json 有这样的东西,它应该可以正常工作:
{
"index": "main page title",
"contact": "Contact page title"
}