0

我的问题如下:我正在尝试重构一个网站并将所有字符串替换为一些变量,因此当我更改一个变量时,它会在整个网站上发生变化。然而,问题来了:

我在多个 Json 文件中有数据,我通过 gulp 得到它:

var locals = {
// Content
someContent: require('../data/content-path.json'),
someOtherContent: require('../data/other-content-path.json'),
};

gulp.task('jade:pages', function() {
    return gulp.src(pages)
        .pipe(plumber())
        .pipe(jade({
            locals: locals
        })
        .on('error', notify.onError({
            title: 'Jade Error',
            message: '<%= error.message %>'
        })))
        .pipe(gulp.dest('dist'));
});

所以我可以像 #{someContent.key1} 这样轻松地从 Jade 访问任何密钥。

但是,如果我想在 someOtherContent 中使用 someContent 中的某个键,它会将其呈现为字符串(不解析变量)。

一些内容

{
    "key1" : {
        "subkey1": "5",
        "subkey2": "9"
    },
    "key2":"<p>Some markup which parsed as html if desirable</p>",
}

一些其他内容

{
    "title": "#{someContent.key1.subkey1} some other text"
}

因此,如果我直接在 Jade 中使用它,它就可以完美地工作,但如果我将它用作#{someOtherContent.title},它就无法解析这样的引用,并且它会准确输出

"#{someContent.key1.subkey1} some other text"

当我希望它输出这个而不是

"5 some other text"

我可以在这里做些什么来让它发挥作用?非常感谢任何帮助。谢谢大家。

4

0 回答 0