【问题标题】:Read a filename from json and include it by jekyll从 json 读取文件名并由 jekyll 包含它
【发布时间】:2015-09-16 08:06:30
【问题描述】:

让你假设我有这个 json 文件:

{
    "components":[
        {
                "id" : "brandbar",
                "name" : "brandbar.html",
                "type":"navbar",
                "description":"Bar with the brand",
                "status": "draft"
        },
        {       
                "id":"topbar",
                "type":"navbar",
                "component":"Best brand",
                "description":"Chart with Date"
        }]
}

现在,我想在这个 json 上创建一个循环来检索文件名。

{% for entry in site.data.component.components %}
                <div class="col-md-12">
                     {% include {{ entry.name }} %}
                </div>
                {% endfor %} 

问题是我不能在我的 include 语句中使用 {{ entry.name }}。

有没有办法实现这个目标? 我不想直接在我的文件夹中循环...我想要一个主文件,我将在其中填写有关组件的每个重要属性。

【问题讨论】:

标签: json html jekyll


【解决方案1】:

您可以尝试使用空格而不是制表符来缩进 json。

这可能会奏效:

{"components":[
    {
        "id" : "brandbar",
        "name" : "brandbar.html",
        "type":"navbar",
        "description":"Bar with the brand",
        "status": "draft"
    },
    {       
        "id":"topbar",
        "type":"navbar",
        "component":"Best brand",
        "description":"Chart with Date"
    }
]}

除了 topbar 没有名称属性,这可能会导致错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 2017-12-25
    • 2012-05-14
    • 2016-12-08
    • 2019-08-26
    • 2017-06-15
    • 2018-06-16
    • 1970-01-01
    相关资源
    最近更新 更多