{"id":24316449,"url":"https://github.com/daun/statamic-utils","last_synced_at":"2025-09-27T00:32:12.188Z","repository":{"id":268240367,"uuid":"903743351","full_name":"daun/statamic-utils","owner":"daun","description":"A collection of utilities for use in Statamic projects","archived":false,"fork":false,"pushed_at":"2025-01-06T18:06:08.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T19:17:21.773Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-15T13:02:05.000Z","updated_at":"2025-01-06T18:06:12.000Z","dependencies_parsed_at":"2024-12-15T13:39:58.962Z","dependency_job_id":"de5a91cb-2d33-42dc-8011-d546497c4179","html_url":"https://github.com/daun/statamic-utils","commit_stats":null,"previous_names":["daun/statamic-utils"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstatamic-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstatamic-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstatamic-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstatamic-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daun","download_url":"https://codeload.github.com/daun/statamic-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234365048,"owners_count":18820590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-17T12:56:34.839Z","updated_at":"2025-09-27T00:32:12.176Z","avatar_url":"https://github.com/daun.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🛠️  Statamic Utils\n\nA collection of utilities I use in [Statamic](https://statamic.com/) projects.\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require daun/statamic-utils\n```\n\n## Registration\n\nModifiers, Tags, Scopes, etc. need to be registered in your app's service provider.\n\n```php\nclass AppServiceProvider extends ServiceProvider\n{\n    public function boot(): void\n    {\n        \\Daun\\StatamicUtils\\Modifiers\\ToIterable::register();\n        \\Daun\\StatamicUtils\\Scopes\\Image::register();\n    }\n}\n```\n\n## Modifiers\n\n### Asset\n\nReturn or find an asset by id or url.\n\n```antlers\n{{# Fetch asset if url was passed #}}\n{{ image = image | asset }}\n```\n\n### Br 2 Nl\n\nStrip tags, but keep line breaks as visually intended by the html.\n\n```antlers\n\u003cp\u003e{{ rich_text | br2nl }}\u003c/p\u003e\n```\n\n### Count Safe\n\nCount the number of items in an array or iterable.\nReturns `0` for null values and `1` for non-iterable values.\n\n```antlers\n{{ if locations | count_safe }} ... {{ /if }}\n```\n\n### Except\n\nRemove keys from an array or collection.\n\n```antlers\n{{ params = get | except('page', 'q') }}\n```\n\n### Is Current\n\nCheck if the current page matches the given URL. Pass `true` to also include ancestors in the comparison.\n\n```antlers\n{{ if url | is_current }}\n    aria-current=\"page\"\n{{ elseif url | is_current(true) }}\n    aria-current=\"true\"\n{{ /if }}\n```\n\n### Is String\n\nCheck if a value is a string.\n\n```antlers\n{{ if some_var | is_string }}\n```\n\n### Max\n\nReturn the highest value in an array or collection.\n\n```antlers\n{{ large = sizes | max }}\n```\n\n### Min\n\nReturn the lowest value in an array or collection.\n\n```antlers\n{{ small = sizes | min }}\n```\n\n### Nl 2 Str\n\nReplace newlines with a specified string.\n\n```antlers\n\u003cp\u003e{{ rich_text | nl2str(', ') }}\u003c/p\u003e\n```\n\n### P 2 Br\n\nConvert paragraph tags to line breaks.\n\n```antlers\n\u003cp\u003e{{ rich_text | p2br }}\u003c/p\u003e\n```\n\n### Push\n\nPush an item onto an array or collection.\n\n```antlers\n{{ items = (items | push:{newitem}) }}\n```\n\n### Resolve\n\nResolves unfetched query builder queries to their results. Useful when passing around entries\nfield values in combination with `nocache` tags to avoid serialization issues.\n\n```antlers\n{{ partial:partials/data-table :rows=\"news | resolve\" }}\n```\n\n### To Int\n\nConvert a value to an integer. Special case: converts a mixed array to an array of integers.\n\n```antlers\n{{ number_array = mixed_array | to_int }}\n```\n\n### To Float\n\nConvert a value to a float. Special case: converts a mixed array to an array of floats.\n\n```antlers\n{{ number_array = mixed_array | to_float }}\n```\n\n### To Iterable\n\nWrap a value in an array if it is not already iterable.\n\n```antlers\nLocations: {{ (locations ?? location) | to_iterable | pluck('title') | list }}\n```\n\n## Tags\n\n### Capture\n\nCapture the output of a template section and assign it to a variable. Similar to assigning the output\nof a partial view to a variable, but without the need for an actual partial file.\n\n```antlers\n{{ capture:contents }}\n    Any output inside of this will land in the `contents` variable.\n{{ /capture:contents }}\n```\n\nAn optional `trim` parameter will trim the output of whitespace.\n\n```antlers\n{{ capture:contents trim=\"true\" }}\n    {{ title }}\n{{ /capture:contents }}\n```\n\nAn optional `when` parameter will only render and capture the output if the condition is met.\n\n```antlers\n{{ capture:contents :when=\"count \u003e= 1\" }}\n    Found {{ count }} results\n{{ /capture:contents }}\n```\n\n### Icon\n\nRender an SVG icon from an existing sprite map.\n\n```antlers\n{{ icon:search }}\n```\n\n```html\n\u003csvg class=\"icon icon-search\" preserveAspectRatio=\"xMinYMid\" aria-hidden=\"true\"\u003e\n    \u003cuse xlink:href=\"#icon-search\"\u003e\n\u003c/svg\u003e\n```\n\n### IfContent\n\nRender a block of content only if it is not empty, i.e. if it contains actual text content. A block\nof content containing only whitespace or empty tags will not be rendered.\n\n```antlers\n{{ if_content }}\n    \u003cul\u003e\n        {{ categories }} \u003cli\u003e{{ title }}\u003c/li\u003e {{ /categories }}\n        {{ tags }} \u003cli\u003e{{ title }}\u003c/li\u003e {{ /tags }}\n    \u003c/ul\u003e\n{{ /if_content }}\n```\n\n## Query Scopes\n\nApply [query scopes](https://statamic.dev/extending/query-scopes-and-filters) to narrow down query results.\n\n- `Published`: Filter out unpublished entries\n- `Image`: Filter assets that are images (pixel + vector)\n- `ImagePixel`: Filter assets that are pixel images (jpeg, png, gif, etc)\n- `ImageVector`: Filter assets that are vector images (svg)\n- `ImageOrVideo`: Filter assets that are images or videos\n- `Video`: Filter assets that are video files\n- `Audio`: Filter assets that are audio files\n\n## Search Filters\n\nClasses for [filtering entries](https://statamic.dev/search#filtering-searchables) for search indexing.\n\n- `Published`: Filter out unpublished entries.\n- `All`: Include all entries, regardless of their published status.\n\n```php\nreturn [\n    'indexes' =\u003e [\n        'articles' =\u003e [\n            'searchables' =\u003e 'collection:articles',\n            'filter' =\u003e \\Daun\\StatamicUtils\\Search\\Filters\\Published::class,\n        ]\n    ]\n];\n```\n\n## Search Transformers\n\nClasses for [transforming fields](https://statamic.dev/search#transforming-fields) for search indexing.\n\n- `BardText`: Extract [plain text](https://statamic.dev/modifiers/bard_text) from a Bard field.\n- `RelationshipTitle`: Map relationship fields to an array of titles.\n\n```php\nreturn [\n    'indexes' =\u003e [\n        'articles' =\u003e [\n            'searchables' =\u003e 'collection:articles',\n            'transformers' =\u003e [\n                'content' =\u003e \\Daun\\StatamicUtils\\Search\\Transformers\\BardText::class,\n                'categories' =\u003e \\Daun\\StatamicUtils\\Search\\Transformers\\RelationshipTitle::class,\n            ]\n        ]\n    ]\n];\n```\n\n## Cache\n\n### Query Params\n\nGet an up-to-date list of marketing query params to ignore when caching a page.\n\n```php\n// config/statamic/static_caching.php\n\nreturn [\n    'disallowed_query_strings' =\u003e \\Daun\\StatamicUtils\\Cache\\QueryParams::toIgnore()\n];\n```\n\n## Utilities\n\n### Data Resolution\n\nThe `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.\n\n```php\nuse Daun\\StatamicUtils\\Data\\Resolver;\n\n$value = /* query builder, wrapped in value object */;\n$actual = Resolver::actual($value);\n\n```\n\n### Control Panel\n\n#### Translations\n\nEnsure the existence of customized `Create Entry` buttons for all data types. Throws an exception if\na collection or taxonomy is missing the required translation key.\n\n```php\n\\Daun\\StatamicUtils\\ControlPanel\\Translations::ensureCreateButtonLabels();\n```\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaun%2Fstatamic-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaun%2Fstatamic-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaun%2Fstatamic-utils/lists"}