返回提示词目录第 1485 页

开发 Shopify 主题内容区块

为 Shopify 主题编写可配置的 Liquid 区块,完善响应式图片、样式隔离、编辑器兼容和无障碍交互。

完整提示词

<context>
Theme sections go wrong in predictable ways: a schema with no presets, so the section never appears in the theme editor's Add section list; settings with no defaults, so a new section renders empty or broken; full-size images with no `srcset`, lazy-loading on the hero image that should load first; CSS that leaks into the rest of the theme because it is not scoped to the section instance; sliders that trap keyboard users and ignore reduced-motion preferences; JavaScript that breaks when the merchant edits the section live in the editor; merchant text printed into attributes without escaping; and hard-coded English strings in a theme that is translated. A good section looks right with no configuration, gives merchants a few clear controls, and costs the storefront almost nothing.
</context>

<task>
Build a theme section for this purpose:

<purpose>
{{section_purpose}}
</purpose>

{{#theme_notes}}
Theme notes: {{theme_notes}}
{{/theme_notes}}
{{#settings}}
Merchant controls requested: {{settings}}
{{/settings}}

1. Inspect the theme: the folder structure (`sections/`, `snippets/`, `blocks/`, `assets/`, `locales/`), two or three existing sections to copy their conventions (class naming, color schemes, spacing settings, how CSS and JavaScript are included, translation keys in schema), and whether the theme uses section groups or theme blocks. If the purpose or controls are unclear enough to change the schema, ask and stop.
2. Design the schema: section-level settings and repeatable blocks with sensible types (text, rich text, image picker, URL, select, range with min, max and step, checkbox, and the theme's color scheme setting if it has one), a default for every setting, a block limit where a large number would hurt layout or performance, presets so merchants can add the section with sample content, and template restrictions if the section only makes sense on some pages. Use translation keys for labels if the theme does.
3. Write the markup in Liquid: semantic HTML with a heading level the merchant can choose where it matters; responsive images through the `image_url` and `image_tag` filters with widths and `sizes` matched to the layout; lazy loading except for an image likely to be above the fold; alt text from the image with a sensible fallback; a tidy placeholder or blank state when no content is set; and `| escape` on merchant text used in attributes. Use `render` (not `include`) for snippets.
4. Style it: scope every rule to the section instance (for example via the section id) or a unique section class, follow the theme's spacing and typography tokens, design mobile first, and do not override global styles.
5. Add JavaScript only if the section needs behaviour: a small custom element or module loaded deferred, no jQuery or new dependencies, re-initialised on the theme editor's section load and unload events and cleaned up on unload, and, for sliders, keyboard controls, visible focus, pause controls, `prefers-reduced-motion` respected, and autoplay off by default.
6. Verify: run the theme's linter (Theme Check through the Shopify CLI, if installed), preview the section on a development theme, add it from the theme editor, try every setting including empty and maximum content, check keyboard navigation and a mobile viewport, and run a Lighthouse check on the page if possible. Report what you could and could not run.
</task>

<constraints>
- Work on a development or unpublished theme only. Never push to or publish the live theme.
- Change only the new section's files, plus locale strings and one shared snippet if needed; say if anything else must change, and why.
- No third-party scripts, tracking, app embeds or external fonts unless asked.
- Never hard-code store-specific content, prices or URLs in the section; everything a merchant might change is a setting or block.
{{> guardrails/scope-discipline}}
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Section summary
Two or three sentences: what the section does and where it can be used.
## Files
One line per file created or changed.
## Merchant settings
Table: setting or block, type, default, what it controls.
## Accessibility and performance
Bullets on image loading, CSS scoping, JavaScript weight and keyboard and screen-reader behaviour.
## Verification
Each check run and its real result, and anything not run with the reason.
</output_format>

可替换内容

  • {{section_purpose}}
  • {{#theme_notes}}
  • {{theme_notes}}
  • {{/theme_notes}}
  • {{#settings}}
  • {{settings}}
  • {{/settings}}
  • {{> guardrails/scope-discipline}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、Shopify 主题、Liquid 开发、响应式设计、主题编辑器

前往 AI 图片创作