跳到正文
14 天免费试用,无需银行卡9 种语言176 种业务类型 · 50 个应用
ZH· USD
试用在线演示免费试用

此页面暂无简体中文版本,现以英文显示。

Marketplace widgets: fields, template and CSS

A widget.json is data: typed fields the owner fills, a logic-less always-escaped template and CSS that the platform scopes to the block. No widget code runs on the server.

  • about 9 min

A marketplace widget (zmle.widget/1) is a page-builder section. The owner installs it, adds the block Marketplace widget to a page, picks your widget and fills its fields. The platform renders your template with the values, escapes them, runs the output through an allow-list sanitiser and scopes your CSS.

examples/marketplace/widget-feature-cards/widget.json (abridged)
{
  "format": "zmle.widget/1",
  "name": "Feature cards",
  "version": "1.0.0",
  "fields": [
    { "key": "heading", "type": "text", "label": "Heading", "default": "Why customers choose us" },
    { "key": "accent", "type": "color", "label": "Accent colour", "default": "#0f766e" },
    { "key": "showNumbers", "type": "boolean", "label": "Number the cards", "default": true },
    { "key": "cards", "type": "list", "label": "Cards", "max": 12, "fields": [
      { "key": "title", "type": "text", "label": "Title" },
      { "key": "text", "type": "textarea", "label": "Text" }
    ] },
    { "key": "link", "type": "url", "label": "Button link", "default": "/contact" }
  ],
  "template": "<section class=\"fc\"><h2>{{heading}}</h2><ul class=\"fc-grid\">{{#each cards}}<li class=\"fc-card\">{{#if showNumbers}}<span class=\"fc-n\">{{@number}}</span>{{/if}}<h3>{{title}}</h3><p>{{text}}</p></li>{{/each}}</ul>{{#if link}}<a class=\"fc-btn\" href=\"{{link}}\">Contact us</a>{{/if}}</section>",
  "css": ".fc-n { background: var(--w-accent); color: #fff; } @media (max-width: 640px) { .fc-grid { grid-template-columns: 1fr; } }"
}
Field typeValue
text / textareaA string (≤ max; defaults 200 / 2,000); always printed as text
urlhttps://…, /path, mailto: or tel: — anything else becomes empty
imagehttps://… or /uploads/…, picked from the media library
color#rgb / #rrggbb, also available in CSS as --w-<key>
number, boolean, selectA number within min / max; true / false; one of options (required)
listItems with their own fields (no nested lists)
  • Keys match ^[a-z][a-zA-Z0-9_]{0,31}$, are unique, at most 30 fields; default fills new blocks.
  • Template: {{key}} (always HTML-escaped), {{#if}} … {{else}} … {{/if}}, {{#unless}}, {{#each list}} with {{@index}} / {{@number}}; at most 6 nested blocks and 20,000 characters. No {{{raw}}}, helpers or partials; every name must be a declared field.
  • Refused in the template: <script>, <style>, <iframe>, <form>, <input>, <link>, <meta>, <base>, <object>, <embed>, on…= handlers, and literal remote files (src="https://…" would track visitors — use an image field).
  • CSS is prefixed with the block ([data-mw="…"] .your-class); url(…), @import, @font-face, expression(), < and backslash escapes are refused; 20,000 characters max.

Written from: docs/DEVELOPERS/WIDGET-SPEC.md, examples/marketplace/widget-feature-cards/widget.json, src/lib/marketplace/widget-core.ts, src/lib/blocks/types.ts