el-schneider/statamic-choices 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

el-schneider/statamic-choices

Composer 安装命令:

composer require el-schneider/statamic-choices

包简介

Card-style choice fieldtype for Statamic

README 文档

README

Statamic Choices

Statamic Choices

Help editors make better decisions. Turn radios and checkboxes into visual choice cards.

A plain radio group asks editors to pick a word. Choices lets you show what they're actually picking — an image, a description, or trusted custom HTML when words won't cut it.

Features

  • Single or multiple: Behaves like radios or checkboxes
  • Rich cards: Label, image, description, or some fine custom HTML per option
  • Two variants: Content cards for text-led choices, image cards when the picture is the choice
  • Frontend-ready: Augments to full option objects with resolved assets

Requirements

  • Statamic 5 or 6
  • PHP 8.3+

Installation

composer require el-schneider/statamic-choices

Usage

Add a Choices field to your blueprint and configure the available options.

Single choice

plan:
  type: choices
  display: Plan
  mode: single
  card_width: 50
  variant: content
  options:
    - value: basic
      label: Basic
      image: assets::cards/basic.svg
      description: Simple publishing workflow for small teams.
    - value: pro
      label: Pro
      image: assets::cards/pro.svg
      description: More automation and editorial flexibility.
      use_html: true
      html:
        code: '<span class="badge-sm">Popular</span>'
    - value: enterprise
      label: Enterprise
      image: assets::cards/enterprise.svg
      description: Advanced controls for large organizations.

Saved value:

plan: pro

Multiple choices

addons:
  type: choices
  display: Add-ons
  mode: multiple
  card_width: 33
  variant: content
  options:
    - value: analytics
      label: Analytics
      image: assets::cards/analytics.svg
      description: Include dashboard and conversion reporting.
    - value: support
      label: Priority support
      image: assets::cards/support.svg
      description: Faster response times from the support team.

Saved value:

addons:
  - analytics
  - support

Configuration Reference

Field settings

Setting Values Default Description
mode single, multiple single Whether the field behaves like radios or checkboxes.
variant content, image content Content cards show labels/text. Image cards use full-bleed images.
card_width 100, 50, 33, 25, 20 100 Approximate card width before wrapping.
image_aspect 1/1, 4/3, 16/9 1/1 Image card aspect ratio. Only used by variant: image.
default scalar or YAML array Default selected value(s).

Option settings

Setting Description
value Stored value. Must be unique.
label Human-readable label shown in the control panel and augmented output. Falls back to value.
image Optional Statamic asset. Use normal asset IDs like assets::cards/basic.svg.
description Optional supporting text for content cards.
use_html Enables trusted custom HTML for content cards. When enabled, HTML replaces image and description.
html Trusted HTML rendered inside the card. No Antlers rendering.

Custom HTML

Content cards can swap their image and description for trusted custom HTML. Intended for blueprint configuration — not editor input. No Antlers.

options:
  - value: pro
    label: Pro
    use_html: true
    html:
      code: '<span class="badge-sm">Popular</span>'

Labels and selection controls stay under fieldtype control.

Image Cards

Image cards are useful for visual presets, colorways, layouts, or other choices where the image is the interface.

layout:
  type: choices
  mode: single
  variant: image
  card_width: 25
  image_aspect: 4/3
  options:
    - value: editorial
      label: Editorial
      image: assets::layouts/editorial.jpg
    - value: portfolio
      label: Portfolio
      image: assets::layouts/portfolio.jpg

In image mode, labels are used for tooltips and accessible names. Descriptions and custom HTML are ignored.

Frontend Usage

The field stores only selected values. When augmented, it returns the selected option data.

Single mode

{{ plan }}
  <h2>{{ label }}</h2>
  {{ if image }}<img src="{{ image:url }}" alt="{{ image:alt }}">{{ /if }}
  {{ if description }}<p>{{ description }}</p>{{ /if }}
{{ /plan }}

Augmented shape:

[
    'value' => 'pro',
    'label' => 'Pro',
    'use_html' => false,
    'image' => Statamic\Contracts\Assets\Asset::class,
    'description' => 'More automation and editorial flexibility.',
    'html' => null,
]

Multiple mode

{{ addons }}
  <div class="addon-card">
    <h3>{{ label }}</h3>
    {{ if image }}<img src="{{ image:url }}" alt="{{ image:alt }}">{{ /if }}
    {{ if description }}<p>{{ description }}</p>{{ /if }}
  </div>
{{ /addons }}

Multiple selections are returned in the option order from the blueprint.

Notes

  • Unknown saved values are ignored.
  • Unprefixed image paths only resolve when exactly one asset container is configured. Prefer explicit IDs like assets::path/to/image.svg.

Development

npm run build
./vendor/bin/pest
./vendor/bin/pint --test
npm run format:check

License

MIT

el-schneider/statamic-choices 适用场景与选型建议

el-schneider/statamic-choices 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 el-schneider/statamic-choices 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 el-schneider/statamic-choices 我们能提供哪些服务?
定制开发 / 二次开发

基于 el-schneider/statamic-choices 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-09