daun / statamic-utils
A collection of utilities for use in Statamic projects
Requires
- php: ^8.1
- laravel/framework: ^10.0 || ^11.0
- statamic/cms: ^5.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.5
- pestphp/pest: ^3.5
- pestphp/pest-plugin-laravel: ^3.0
This package is auto-updated.
Last update: 2025-01-19 21:53:16 UTC
README
A collection of utilities I use in Statamic projects.
Installation
Install the package via composer:
composer require daun/statamic-utils
Modifiers
Is String
Check if a value is a string.
{{ if some_var | is_string }}
Asset
Return or find an asset by id or url.
{{# Fetch asset if url was passed #}} {{ image = image | asset }}
Count Safe
Count the number of items in an array or iterable.
Returns 0
for null values and 1
for non-iterable values.
{{ if locations | count_safe }} ... {{ /if }}
Max
Return the highest value in an array or collection.
{{ large = sizes | max }}
Min
Return the lowest value in an array or collection.
{{ small = sizes | min }}
P 2 Br
Convert paragraph tags to line breaks.
<p>{{ rich_text | p2br }}</p>
Push
Push an item onto an array or collection.
{{ items = (items | push:{newitem}) }}
To Iterable
Wrap a value in an array if it is not already iterable.
Locations: {{ (locations ?? location) | to_iterable | pluck('title') | list }}
Utilities
Control Panel
Translations
Ensure the existence of customized Create Entry
buttons for all data types. Trows an exception if
a collection or taxonomy is missing the required translation key.
\Daun\StatamicUtils\ControlPanel\Translations::ensureCreateButtonLabels();