Helper Functions
Kompass registers a set of global helper functions (in src/Helpers/helpers.php) that are available everywhere — Blade views, controllers, Livewire components, and service classes — without any use import. They are the everyday API you reach for inside block views and frontend templates.
All helpers are guarded with function_exists(), so you can safely override any of them in your own application.
Fields & meta
These read values out of a block's datafield collection and its meta. They are the functions you use most when building a block's Blade view.
get_field()
get_field(string $type, $data, ?string $class = null, ?string $size = null, mixed $default = null): mixedReturns the value of the first datafield matching $type. For image / gallery fields it returns rendered <picture> HTML (using $class and $size); for video / poster it returns the file URL; for everything else, the raw stored value.
@php
$title = get_field('text', $item->datafield);
$title = get_field('text', $item->datafield, default: 'Untitled');
$image = get_field('image', $item->datafield, 'w-full rounded', 'thumbnail');
@endphpget_fields()
get_fields(string $type, $data): arrayLike get_field(), but returns all matching field values as an array — use it for repeatable fields (e.g. a list of links).
$links = get_fields('link', $item->datafield);get_field_as()
get_field_as(string $type, $data, string $cast = 'string', mixed $default = null): mixedget_field() with a type cast. $cast is one of int, bool, array, object, or string.
$limit = get_field_as('limit', $item->datafield, 'int', 10);
$isActive = get_field_as('active', $item->datafield, 'bool', false);get_meta()
get_meta(object $item, string $key, mixed $default = null): mixedReads a per-block setting from the block's meta, with a fallback. Equivalent to $item->getMeta($key) but null-safe and with a default.
<div class="card {{ get_meta($item, 'css-classname', 'bg-white') }}">get_thumbnails()
get_thumbnails($id_media, $class = null, $size = null): stringRenders a media file (by ID) as responsive <picture> HTML, or an empty string if the file is missing.
Blocks & editor
Utilities for working with block structure and the Kompass Editor content format.
block_grid_classes()
block_grid_classes(mixed $item): arrayReturns ['gridCols' => 'md:grid-cols-N', 'colSpan' => 'md:col-span-N'] derived from the block's layoutgrid — used by Layout Blocks to build their responsive grid.
wysiwyg_blocks()
wysiwyg_blocks(mixed $item = null, $field = null): arrayNormalises stored WYSIWYG content into the canonical render array. Accepts a block item, a raw field, an array, or a string, and transparently upgrades legacy Editor.js data. Use it before rendering rich text.
$blocks = wysiwyg_blocks($item);block_registry() / field_registry()
block_registry(): BlockTypeRegistry
field_registry(): FieldTypeRegistryReturn the single-source-of-truth registries for the configured block types and field types.
to_compiled_array() / to_compiled_object()
to_compiled_array(mixed $input): array
to_compiled_object(mixed $input): objectNormalise blocks data of any shape into a flat array, or a wrapped object, respectively.
Relationship queries
These power the Relationship Block — resolving registered sources and running their queries. See that page for the full data model and item-view contract.
query_models()
query_models(): arrayReturns the registered queryable sources, keyed by source key. Merges the config-defined kompass.query_models entries with the admin-managed query_sources table (config wins on a key collision). Database sources are filtered against the kompass.query_source_models allow-list.
kompass_query()
kompass_query($block): CollectionRuns a Relationship block's configured query and returns the matched records. Auto mode applies status/scope, ordering, direction, and limit; manual mode returns the curated selection in saved order. Returns an empty collection when nothing is configured.
kompass_query_candidates()
kompass_query_candidates(string $modelKey, int $limit = 50, ?string $search = null): CollectionSelectable records for the manual-selection picker. An optional $search term filters server-side across the source's display_fields.
kompass_query_url()
kompass_query_url(string $modelKey, $record): ?stringBuilds a record's frontend URL from the source's url_pattern ({slug} is replaced with the record's slug). Returns null when the source has no pattern.
kompass_query_label()
kompass_query_label(string $modelKey, $record): stringA human label for a record — the source's display_fields joined with ·, falling back to #id.
kompass_apply_scope()
kompass_apply_scope($query, string $modelClass, ?string $scope): voidApplies a named Eloquent local scope to a query, but only when the model actually defines it — a guard against calling arbitrary methods from admin-supplied config.
Settings & SEO
setting()
setting($key = null, $default = null)Reads a global setting by its dot-notated group.key. Called with no argument it returns the whole settings collection.
{{ setting('global.webtitle', 'Kompass') }}See Global Settings for the available groups.
seo()
seo(): SeoServiceReturns the fluent SeoService for building <title>, <meta>, and Open Graph / Twitter tags. See SEO for the full method reference and how the default page.blade.php uses it.
seo()->title($page->title)->description($page->meta_description);Assets & images
kompass_asset()
kompass_asset($path, $secure = null): stringBuilds a URL to a published Kompass asset under vendor/kompass/assets/. See Publishing Assets.
getImageID() / getImageUrl()
getImageID($id, $sizeKey = null)
getImageUrl($url, $sizeKey = null)Resolve a processed image (responsive size variant) by media ID or by source URL, respectively. See Media Library for image sizes and conversions.
Overriding a helper
Because every helper is wrapped in if (! function_exists(...)), you can define your own version earlier in the boot process (e.g. in an autoloaded file) to replace Kompass's implementation.