0

我基于 Jekyll 创建了一个新的 Netlify CMS 网站并创建了新的集合workshopconsultant

使用 Netlify CMS 界面,我可以查看、添加、编辑和删除新集合,但无法在视图中检索它们。

--/_consultants
   name.md

--/_workshops
   title.md

配置.yml

collections:
  # WORKSHOPS
  - name: "workshop" # Used in routes, ie.: /admin/collections/:slug/edit
    label: "Workshop" # Used in the UI, ie.: "New Post"
    folder: "_workshops" # The path to the folder where the documents are stored
    sort: "title:desc" # Default is title:asc
    create: true # Allow users to create new documents in this collection
    slug: "{{slug}}"
    output: true
    permalink: /wokshop/:title
    fields: # The fields each document in this collection have
      - {label: "Title", name: "title", widget: "string", tagname: "h1"}
      - label: "Consultant"
        name: "consultant"
        widget: "relation"
        collection: "consultant"
        searchFields: ["name"]
        valueField: "name"
      - {label: "Location", name: "location", widget: "string"}
      - {label: "Duration", name: "duration", widget: "string"}
      - label: "Category"
        name: "category"
        widget: "select"
        options: ["Business", "Team & Culture", "Design"]
      - {label: "Price", name: "price", widget: "string", required: false}
      - {label: "Permalink", name: "permalink", widget: "hidden"}
      - {label: "Blurb", name: "ws-blurb", widget: "string"}
      - {label: "Description", name: "ws-description", widget: "markdown"}

  # CONSULTANTS
  - name: "consultant" # Used in routes, ie.: /admin/collections/:slug/edit
    label: "Consultant" # Used in the UI, ie.: "New Post"
    folder: "_consultants" # The path to the folder where the documents are stored
    sort: "date:desc" # Default is title:asc
    create: true # Allow users to create new documents in this collection
    slug: "{{slug}}"
    identifier_field: name
    output: true
    fields: # The fields each document in this collection have
      - {label: "Permalink", name: "permalink", widget: "hidden"}
      - {label: "Name", name: "name", widget: "string", tagname: "h1"}
      - label: "Image"
        name: "image"
        widget: "image"
        # default: "/uploads/chocolate-dogecoin.jpg"
        media_library:
          config:
            multiple: false
      - {label: "Bio", name: "bio", widget: "markdown"}
      - {label: "References", name: "references", widget: "markdown"}
      - {label: "Link", name: "link", widget: "string"}
      - {label: "Workshops hosted", name: "ws-hosted", widget: "number"}

当我尝试检索新创建的workshopsconsultants我无法让它工作时:

<ul>
 {% for item in site.workshops %}
  <li>
   <h2>
    {{ item.title }}
   </h2>
  </li>
 {% endfor %}
</ul>

当我尝试调试对象时,它返回 NULL:{{ site.workshops | jsonify }}

最让我困惑的是,我可以通过管理界面访问这些集合,但在过去的 4 个小时里,我未能在视图中检索它们。

我错过了什么?

4

1 回答 1

0

我找到了解决方案!因此,对于任何被困在这一点上的人:以下信息必须转到_config.yml而不是(!)到config.yml

collections:
  workshops:
    output: true
  consultants:
    output: true
于 2019-08-29T09:11:33.400 回答