首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在Prismic.io自定义类型中添加键值对对象?

有没有办法在Prismic.io自定义类型中添加键值对对象?
EN

Stack Overflow用户
提问于 2021-06-29 06:49:36
回答 1查看 38关注 0票数 0

Prismic的文档有点模糊,而且他们的社区形式并不是真正的超级响应式的,所以我想我也应该在这里问一下。在我拥有的自定义类型(产品)中,我希望创建一个(变体)的组中继器,我可以用它来指定产品的‘版本’(例如,视频包将有不同的分辨率和编解码器选项)。我想要的前端,‘漂亮’的版本显示在前端,我希望网址安全,小写的实际后端的值。

示例:

代码语言:javascript
复制
variants: {
  'H.264': 'h264',
  'ProRes': 'prores',
  'MP4': 'mp4'
}

另一个例子:

代码语言:javascript
复制
variants: {
  '44.1kHz': '44khz',
  '48kHz': '48khz',
  '96kHz': '96khz
}

解决方案一是它变得有点复杂,就像上面的例子一样,我可以只使用.replace(/\s/g, '_').replace(/./g, '').toLowerCase()将其'hack‘为后端可用的代码(它将匹配)。然而,对于分辨率,它变得有点复杂:

代码语言:javascript
复制
variants: {
  '1920 x 1080': '1920x1080',
  '1080 x 1920': '1080x1920',
  '1080 (Square)': '1080x1080',
  '4K': '4k'
}

我想,如果我能找到一种方法,在Prismic中创建一个可重复的键/值映射,我就可以创建我需要的任何变体,并使其足够抽象,以便在未来的任何变体中工作。

下面是我的自定义类型的json:

代码语言:javascript
复制
{
  "Main" : {
    "title" : {
      "type" : "StructuredText",
      "config" : {
        "single" : "heading1",
        "label" : "Title",
        "placeholder" : "Product Title"
      }
    },
    "uid" : {
      "type" : "UID",
      "config" : {
        "label" : "UID",
        "placeholder" : "The unique identifier"
      }
    },
    "category" : {
      "type" : "Link",
      "config" : {
        "select" : "document",
        "customtypes" : [ "category" ],
        "label" : "Category",
        "placeholder" : "Product Category"
      }
    },
    "featured_image" : {
      "type" : "Image",
      "config" : {
        "constraint" : { },
        "thumbnails" : [ {
          "name" : "thumb",
          "width" : 150,
          "height" : null
        }, {
          "name" : "small",
          "width" : 300,
          "height" : null
        }, {
          "name" : "medium",
          "width" : 600,
          "height" : null
        }, {
          "name" : "large",
          "width" : 900,
          "height" : null
        }, {
          "name" : "xl",
          "width" : 1200,
          "height" : null
        } ],
        "label" : "featured image"
      }
    },
    "product_primary_color" : {
      "type" : "Color",
      "config" : {
        "label" : "Product Primary Color"
      }
    },
    "short_description" : {
      "type" : "StructuredText",
      "config" : {
        "single" : "paragraph",
        "label" : "Short Description",
        "placeholder" : "The one-liner description"
      }
    },
    "price" : {
      "type" : "Number",
      "config" : {
        "label" : "Price",
        "placeholder" : "The regular price"
      }
    },
    "sale_price" : {
      "type" : "Number",
      "config" : {
        "label" : "Sale Price",
        "placeholder" : "Sale price (if any)"
      }
    },
    "on_sale" : {
      "type" : "Boolean",
      "config" : {
        "default_value" : false,
        "label" : "On sale?"
      }
    },
    "base_download_link" : {
      "type" : "Link",
      "config" : {
        "label" : "Base Download Link",
        "placeholder" : "This is the bucket-level link for product",
        "select" : null
      }
    },
    "upsell_items" : {
      "type" : "Group",
      "config" : {
        "fields" : {
          "upsell_item" : {
            "type" : "Link",
            "config" : {
              "select" : "document",
              "customtypes" : [ "product" ],
              "label" : "Upsell Item",
              "placeholder" : "This are the items that can be upsold/cross-sold"
            }
          }
        },
        "label" : "upsell_items"
      }
    },
// Variants are here ============================================
    "variants" : {
      "type" : "Group",
      "config" : {
        "fields" : {
          "variant" : {
            "type" : "Text",
            "config" : {
              "label" : "variant",
              "placeholder" : "A variant (resolution/sample rate/etc) for the download path on S3"
            }
          }
        },
        "label" : "variants"
      }
    },
    "body" : {
      "type" : "Slices",
      "fieldset" : "Slice zone",
      "config" : {
        "labels" : { },
        "choices" : {
          "embed_slice" : {
            "type" : "SharedSlice"
          },
          "image_text_slice" : {
            "type" : "SharedSlice"
          },
          "wide_text_slice" : {
            "type" : "SharedSlice"
          }
        }
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-06-29 18:07:41

这在目前是不可能的,但我们将其作为一个开放的功能请求进行跟踪,并在这里提供一个解决方法:https://community.prismic.io/t/iterating-select-values-in-template-from-other-document/818/2

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68170775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档