json - 使用 twig include 将静态 json 文件中的 json 添加到 index.twig
问题描述
我在树枝上与 json 作斗争。我想在我的 twig 文件中包含一个静态 json 文件并将其传递给其中的一个 twig 包含。
我有我的索引树枝文件,其中有我的 STATIC json 文件包括和树枝包括:
{% set json %}
{% include "content.json" %}
{% endset %}
{% include '@partials/blocks/site-header.twig' with {json:json} %}
在我的 siteheader.twig 中,我想将我的导航呈现为:
{% for headerNav in json %}
<a class="button button--nav" href="#">
{{headerNav.text}}
</a>
{% endfor %}
我的 content.json 看起来像这样:
{
"headerNav":[
{
"text": "Link 1"
},
{
"text": "Link 2"
}
]
}
重点是,siteheader 应该能够根据我传入的 json 文件呈现不同的链接。
解决方案
推荐阅读
- reactjs - 如何在与firebase数据库的反应中执行crud操作
- python - 特定页面的Sphinx配置
- youtube - 处理已放弃 无法处理视频
- c++ - 为什么这是打印内存地址而不是值
- php - 从许多变量中选择 3 个最大的数字并使用这些值来回应适当的反应
- asp.net-core - 为什么调用 Breeze metadata() 会返回 .net core 3.0.100 的错误
- python - 如何正确地将大尺寸数组重塑为两个单独的分配?
- azure - 从 Node.js 创建 WebApp 资源时,“参数 LinuxFxVersion 的值无效”
- python-3.x - 返回节点的更改(通过 apoc.trigger)版本而不是原始版本
- node.js - 试图处理 mkdir 抛出的错误