イム:https://github.com/zimmen/gulp-twig別のテンプレートに渡すオブジェクトとしてtwigテンプレートを含めますか?一息-小枝を使って
私は私のコンテナコンポーネントの小枝のファイルがあります。
{# snippet.twig #}
<div class="snippet">
<h2>{{ title }}</h2>
</div>
イムページでこれらをデモ:
{# container.twig #}
<div class="container">
{% for item in items %}
<div class="container__item">
{{ item }}
</div>
{% endfor %}
</div>
を私はまた、スニペットファイルを持っています。小枝。スニペットをコンテナ内の{{item}}としてレンダリングする必要があります。したがって、page.twigを見ると、これは出力でなければなりません:
<div class="container">
<div class="container__item">
<div class="snippet">
<h2>title</h2>
</div>
</div>
<div class="container__item">
<div class="snippet">
<h2>title</h2>
</div>
</div>
<div class="container__item">
<div class="snippet">
<h2>title</h2>
</div>
</div>
</div>
ここでは難しいところです。 container.twigとsnippet.twigは別のアプリケーションに取り込まれています。したがって、container.twig内の{{item}}は{{itemRenderer(item)}}のように変更できません。
しかし、page.twigはどこにも使用されていないので、私はそれを編集することができます。 page.twigに、container.twigやsnippet.twigを変更せずに、itemとしてsnippet.twigを使ってcontainer.twigをレンダリングする方法がありますか?
これは私の一気の作業です:
var gulp = require('gulp'),
config = require('../config'),
utilities = require('../build-utilities'),
src = config.path.src,
dest = config.path.dest,
opts = config.pluginOptions,
env = utils.getEnv(),
plugins = require('gulp-load-plugins')(opts.load);
var compile = function() {
var notProdOrTest = env.deploy && !env.prod && !env.test,
deployPath = env.deployPath,
sources = (env.deploy) ? ((env.styleguide) ? src.twig.styleguide: src.twig.testing): src.twig.all;
return gulp.src(sources, {base: 'src/'})
.pipe(plugins.twig({
data: {
component: utils.getDirectories('src/component/'),
deploy : env.deploy,
test : env.test,
prod : env.prod
}
}))
.pipe(plugins.htmlmin(opts.htmlmin))
.pipe(plugins.tap(function(file){
file.path = file.path.replace('testing/', '');
}))
.pipe((notProdOrTest) ? plugins.replace(/src="\//g, 'src="/' + deployPath.root + '/'): plugins.gutil.noop())
.pipe((notProdOrTest) ? plugins.replace(/href="\//g, 'href="/' + deployPath.root + '/'): plugins.gutil.noop())
.pipe((notProdOrTest) ? plugins.replace(/srcset="\//g, 'srcset="/' + deployPath.root + '/'): plugins.gutil.noop())
.pipe((notProdOrTest) ? plugins.replace(/url\('\//g, 'url(\'/' + deployPath.root + '/'): plugins.gutil.noop())
.pipe(gulp.dest((env.deploy) ? deployPath.markup: dest.markup));
},
watch = function() {
gulp.watch(src.twig.watch, ['twig:compile']);
};
module.exports = {
compile: compile,
watch : watch
};
するスニペットは、すべてのアイテムにのみ前に/項目のリストの後にレンダリングされるべきか? – xabbuh
アイテム用にレンダリングする必要があります。これを明確にするために質問を更新しました。 – Evans
私はあなたの問題を理解していない。あなたは*コンテナ内の項目になることができる別のコンポーネントがたくさんあるので*書きました。必要なときだけこのコードを使用するテストを追加できませんか? –