Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

For a software dev like me who has no idea how to create a cute hand-drawn dashed line, this course just 100% works.

— Ira Zayats, Developer

Toggle Fieldtype

A nice little toggle switch generally used to manage settings-type variables. It stores true or false and is delightfully uncomplicated, just like our relationship with yogurt.

Toggle Fieldtype UI
The Toggle Fieldtype in action!

Data Structure

Flicking the toggle to the right sets to the value to true, left to false.

do_the_thing: true

Templating

Toggles are usually used to control logic, so you can combine them with {{ if }} statements in your templates to handle all manner of show/hide wizardry.

{{ if do_the_thing }} It does it {{ /if }}

The following example uses the fetch helper function, which resolves Value instances for you and returns the underlying value. This way you always get the real "truthy" value, regardless of how you retrieved $do_the_thing.

<?php
use function Statamic\View\Blade\{fetch};
?>
 
@if (fetch($do_the_thing))
It does it
@endif
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →