在header.twig
:
<ul class="nav list-unstyled">
{% for item in data %}
{% include 'partials/item/header/item-nav.twig' %}
{% endfor %}
</ul>
在我的item-nav.twig
中<li><a href="{{ data.url }}">{{ data.menu_name }}</a></li>
header.twig包含在base.twig中。我在base.php文件中渲染了base.twig。我可以在哪里添加数据array
来处理data.url
和data.name
?在base.php?或者我再次呈现文件php?谢谢。
base.php
include __DIR__ . '/../vendor/autoload.php';
$renderer = new \Resilient\TwigRenderer(__DIR__ . '/../vemale-beta-desktop/templates/', ['debug' => true]);
$renderer->addExtension(new Twig_Extension_Debug());
$faker = Faker\Factory::create();
$data = [
'assets_url' => 'http://devel.merdeka.com/ui/2017/april/Vemale/',
'meta_title' => 'Vemale Beta',
'meta_description' => 'Vemale Beta Desktop',
'data' => ['menu_name' => 'PARENTING']
];
/*foreach ( range(0, 10) as $k ) {
$data['data'][] = [ 'title' => $faker->sentence() ];
}*/
$response = $renderer->render(new \Zend\Diactoros\Response(),'base.twig', $data);
$emitter = new Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($response);
答案 0 :(得分:-1)
<强> header.twig 强>
<ul>
{% for item in data %}
{{ include('partials/item-nav.twig') }}
{% endfor %}
</ul>
<强>项-nav.twig 强>
<li><a href="{{ item.<some-property> }}">{{ item.<other-property> }}</a></li>