【问题标题】:Is there any way to create nested repeatable content in Prismic?有没有办法在 Prismic 中创建嵌套的可重复内容?
【发布时间】:2020-04-20 14:55:00
【问题描述】:

我的用例如下:

我有一个带有测验的页面,测验有 N 个部分/问题和 M 个可能的答案。问题和答案都包含多个字段(例如,每个答案的图像、标题和颜色)。我正在使用切片并将问题放在可重复区域中,但您不能在可重复区域内设置组字段。

还有其他方法吗? Wordpress 高级自定义字段可以轻松解决这个问题。

【问题讨论】:

    标签: prismic.io


    【解决方案1】:

    用切片建模应该没有问题。您将拥有像您在不可重复字段中描述的问题及其图像等的切片以及在可重复字段中带有其图像的答案。

    然后在文档编写部分,您将为每个问题调用一个切片,并为每个答案选择“添加一个新元素到组”。

    这是您的内容类型的 json 结构的示例:

    {
      "Main" : {
        "home_title" : {
          "type" : "StructuredText",
          "config" : {
            "single" : "heading1, heading2, heading3, heading4, heading5, heading6",
            "label" : "home title",
            "placeholder" : "Home"
          }
        },
        "body" : {
          "type" : "Slices",
          "fieldset" : "Slice zone",
          "config" : {
            "labels" : {
              "mcq" : [ {
                "name" : "...",
                "display" : ""
              } ]
            },
            "choices" : {
              "Question" : {
                "type" : "Slice",
                "fieldset" : "Question",
                "description" : "Question and answers",
                "icon" : "help",
                "display" : "list",
                "non-repeat" : {
                  "question" : {
                    "type" : "StructuredText",
                    "config" : {
                      "single" : "heading4",
                      "label" : "question"
                    }
                  },
                  "code_snippet" : {
                    "type" : "StructuredText",
                    "config" : {
                      "multi" : "preformatted",
                      "label" : "code snippet"
                    }
                  },
                  "correct_answer" : {
                    "type" : "Number",
                    "config" : {
                      "label" : "Correct answer"
                    }
                  },
                  "answer_explanatrion" : {
                    "type" : "StructuredText",
                    "config" : {
                      "multi" : "paragraph, preformatted, heading3, heading4, heading5, heading6, strong, em, hyperlink, image, embed, list-item, o-list-item, o-list-item",
                      "label" : "Answer explanation"
                    }
                  }
                },
                "repeat" : {
                  "answers" : {
                    "type" : "StructuredText",
                    "config" : {
                      "multi" : "paragraph, preformatted, strong, em, embed",
                      "label" : "Answers"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多