Skip to content

v0.1.12

Choose a tag to compare

@Arthurdw Arthurdw released this 05 Mar 12:07
· 10 commits to main since this release
7baa933

New: Toggle field type

Adds a new toggle field type for conditionally showing/hiding CMS-managed elements on the live site.

API additions

  • PageData.Toggle(key string) bool — returns the boolean field value (false if missing)
  • PageData.ToggleOr(key string, fallback bool) bool — returns CMS value or fallback; returns true when fields is nil (template/sync renders for schema discovery)
  • EntryData.Toggle(key string) bool — same as above for subcollection entries
  • EntryData.ToggleOr(key string, fallback bool) bool — same as above for subcollection entries

Components

  • components.Toggleable(p, key, label, fallback) — wraps content with a toggle control for page-level fields
  • components.ToggleableEntry(e, key, label, fallback) — wraps content with a toggle control for subcollection entries

Usage

// Inline conditional
if p.ToggleOr("show_banner", true) {
    <div data-cms-field="show_banner" data-cms-type="toggle" data-cms-label="Show Banner">
        ...
    </div>
}

// Or use the component wrapper
@c.Toggleable(p, "show_banner", "Show Banner", true) {
    <div class="banner">...</div>
}