PHPackages                             daun/statamic-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. daun/statamic-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

daun/statamic-utils
===================

A collection of utilities for use in Statamic projects

1.11.0(2mo ago)174MITPHPPHP ^8.1CI failing

Since Dec 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/daun/statamic-utils)[ Packagist](https://packagist.org/packages/daun/statamic-utils)[ Docs](https://github.com/daun/statamic-utils)[ RSS](/packages/daun-statamic-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (16)Versions (15)Used By (0)

🛠️ Statamic Utils
=================

[](#️-statamic-utils)

A collection of utilities I use in [Statamic](https://statamic.com/) projects.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require daun/statamic-utils
```

Registration
------------

[](#registration)

Modifiers, Tags, Scopes, etc. need to be registered in your app's service provider.

```
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        \Daun\StatamicUtils\Modifiers\ToIterable::register();
        \Daun\StatamicUtils\Scopes\Image::register();
    }
}
```

Modifiers
---------

[](#modifiers)

### Asset

[](#asset)

Return or find an asset by id or url.

```
{{# Fetch asset if url was passed #}}
{{ image = image | asset }}
```

### Br 2 Nl

[](#br-2-nl)

Strip tags, but keep line breaks as visually intended by the html.

```
{{ rich_text | br2nl }}
```

### Count Safe

[](#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 }}
```

### Except

[](#except)

Remove keys from an array or collection.

```
{{ params = get | except('page', 'q') }}
```

### Is Current

[](#is-current)

Check if the current page matches the given URL. Pass `true` to also include ancestors in the comparison.

```
{{ if url | is_current }}
    aria-current="page"
{{ elseif url | is_current(true) }}
    aria-current="true"
{{ /if }}
```

### Is String

[](#is-string)

Check if a value is a string.

```
{{ if some_var | is_string }}
```

### Max

[](#max)

Return the highest value in an array or collection.

```
{{ large = sizes | max }}
```

### Min

[](#min)

Return the lowest value in an array or collection.

```
{{ small = sizes | min }}
```

### Nl 2 Str

[](#nl-2-str)

Replace newlines with a specified string.

```
{{ rich_text | nl2str(', ') }}
```

### Orientation

[](#orientation)

Determine the orientation of an aspect ratio value. Returns `portrait`, `landscape`, or `square`.

```
{{ orientation = asset:ratio | orientation }}
```

A ratio is considered square if it is within 5% of 1:1. Use the optional first parameter to specify a custom threshold, e.g. `1.25` for a 25% tolerance or `1.0` for a strict 1:1 ratio.

```
{{ orientation = image | orientation(1.25) }}
```

### P 2 Br

[](#p-2-br)

Convert paragraph tags to line breaks.

```
{{ rich_text | p2br }}
```

### Push

[](#push)

Push an item onto an array or collection.

```
{{ items = (items | push:{newitem}) }}
```

### Resolve

[](#resolve)

Resolves unfetched query builder queries to their results. Useful when passing around entries field values in combination with `nocache` tags to avoid serialization issues.

```
{{ partial:partials/data-table :rows="news | resolve" }}
```

### Standard Ratio

[](#standard-ratio)

Map an aspect ratio value to its closest equivalent in a predefined set of standard ratios.

```
{{ ratio = asset:ratio | standard_ratio }}
```

Default ratios are 1:1, 4:3, 3:2, 16:9 and their inverses. You can globally define custom ratios:

```
\Daun\StatamicUtils\Modifiers\StandardRatio::define(['5/4', '4/5']);
```

### To Int

[](#to-int)

Convert a value to an integer. Special case: converts a mixed array to an array of integers.

```
{{ number_array = mixed_array | to_int }}
```

### To Float

[](#to-float)

Convert a value to a float. Special case: converts a mixed array to an array of floats.

```
{{ number_array = mixed_array | to_float }}
```

### To Iterable

[](#to-iterable)

Wrap a value in an array if it is not already iterable.

```
Locations: {{ (locations ?? location) | to_iterable | pluck('title') | list }}
```

### Wrap Words

[](#wrap-words)

Wrap each word in a `` tag. Use the optional first parameter to specify a different wrapper tag.

```
{{ title | wrap_words }}

  {{ title | wrap_words('li') }}

```

Tags
----

[](#tags)

### Capture

[](#capture)

Capture the output of a template section and assign it to a variable. Similar to assigning the output of a partial view to a variable, but without the need for an actual partial file.

```
{{ capture:contents }}
    Any output inside of this will land in the `contents` variable.
{{ /capture:contents }}
```

An optional `trim` parameter will trim the output of whitespace.

```
{{ capture:contents trim="true" }}
    {{ title }}
{{ /capture:contents }}
```

An optional `when` parameter will only render and capture the output if the condition is met.

```
{{ capture:contents :when="count >= 1" }}
    Found {{ count }} results
{{ /capture:contents }}
```

### Icon

[](#icon)

Render an SVG icon from an existing sprite map.

```
{{ icon:search }}
```

```

```

### IfContent

[](#ifcontent)

Render a block of content only if it is not empty, i.e. if it contains actual text content. A block of content containing only whitespace or empty tags will not be rendered.

```
{{ if_content }}

        {{ categories }} {{ title }} {{ /categories }}
        {{ tags }} {{ title }} {{ /tags }}

{{ /if_content }}
```

### Repeat

[](#repeat)

Render the contained content a specified number of times.

```
{{ repeat times="3" }}
    This paragraph will be repeated 3 times.
{{ /repeat }}
```

Actions
-------

[](#actions)

### Edit Collection Mount

[](#edit-collection-mount)

Redirect to the edit form of a collection's mount page from its entry listing view.

### Show Mount Entries

[](#show-mount-entries)

Redirect to the entry listing view of a collection's mount page from its entry edit view.

Query Scopes
------------

[](#query-scopes)

Apply [query scopes](https://statamic.dev/extending/query-scopes-and-filters) to narrow down query results.

- `Published`: Filter out unpublished entries
- `Image`: Filter assets that are images (pixel + vector)
- `ImagePixel`: Filter assets that are pixel images (jpeg, png, gif, etc)
- `ImageVector`: Filter assets that are vector images (svg)
- `ImageOrVideo`: Filter assets that are images or videos
- `Video`: Filter assets that are video files
- `Audio`: Filter assets that are audio files

Search Filters
--------------

[](#search-filters)

Classes for [filtering entries](https://statamic.dev/search#filtering-searchables) for search indexing.

- `Published`: Filter out unpublished entries.
- `All`: Include all entries, regardless of their published status.

```
return [
    'indexes' => [
        'articles' => [
            'searchables' => 'collection:articles',
            'filter' => \Daun\StatamicUtils\Search\Filters\Published::class,
        ]
    ]
];
```

Search Transformers
-------------------

[](#search-transformers)

Classes for [transforming fields](https://statamic.dev/search#transforming-fields) for search indexing.

- `BardText`: Extract [plain text](https://statamic.dev/modifiers/bard_text) from a Bard field.
- `RelationshipTitle`: Return an array of titles of all relationships (entries, terms, etc)
- `RelationshipTitleLocalizations`: Return an array of relationship titles in all languages

```
return [
    'indexes' => [
        'articles' => [
            'searchables' => 'collection:articles',
            'transformers' => [
                'content' => \Daun\StatamicUtils\Search\Transformers\BardText::class,
                'categories' => \Daun\StatamicUtils\Search\Transformers\RelationshipTitle::class,
            ]
        ]
    ]
];
```

Cache
-----

[](#cache)

### Query Params

[](#query-params)

Get an up-to-date list of marketing query params to ignore when caching a page.

```
// config/statamic/static_caching.php

return [
    'disallowed_query_strings' => \Daun\StatamicUtils\Cache\QueryParams::toIgnore()
];
```

Utilities
---------

[](#utilities)

### Data Resolution

[](#data-resolution)

The `Resolver` class provides a way of resolving wrapped data to their actual underlying values. This is useful for value objects, query builders, fluent tags, etc.

```
use Daun\StatamicUtils\Data\Resolver;

$value = /* query builder, wrapped in value object */;
$actual = Resolver::actual($value);
```

### Control Panel

[](#control-panel)

#### Translations

[](#translations)

Ensure the existence of customized `Create Entry` buttons for all data types. Throws an exception if a collection or taxonomy is missing the required translation key.

```
\Daun\StatamicUtils\ControlPanel\Translations::ensureCreateButtonLabels();
```

License
-------

[](#license)

[MIT](https://opensource.org/licenses/MIT)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance86

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~61 days

Total

13

Last Release

73d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ac2b3787ded290b6bac87b937abf4f267483e4da64731bfb256a942bb669ca?d=identicon)[daun](/maintainers/daun)

---

Top Contributors

[![daun](https://avatars.githubusercontent.com/u/22225348?v=4)](https://github.com/daun "daun (67 commits)")

---

Tags

utilitiesstatamic

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/daun-statamic-utils/health.svg)

```
[![Health](https://phpackages.com/badges/daun-statamic-utils/health.svg)](https://phpackages.com/packages/daun-statamic-utils)
```

###  Alternatives

[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

2381.5k10](/packages/marcorieser-statamic-livewire)[aerni/livewire-forms

A Statamic forms framework powered by Laravel Livewire

2912.8k](/packages/aerni-livewire-forms)[visuellverstehen/statamic-classify

A useful helper to add CSS classes to all HTML tags generated by the bard editor.

20116.8k](/packages/visuellverstehen-statamic-classify)[mitydigital/feedamic

A fully-featured RSS and Atom feed generator for Statamic.

1064.0k](/packages/mitydigital-feedamic)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)[swiftmade/statamic-clear-assets

Deletes unused assets. Saves storage space.

1938.6k](/packages/swiftmade-statamic-clear-assets)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
