Note: This document is AI generated, unedited, not systematically tested. So may be correct or not.
A quick reference guide for all Blade helper functions available in BladeHelpers.php.
actionUrl($path, $params, $scheme) - Generate action URL
cpUrl($path, $params, $scheme) - Generate control panel URL
siteUrl($path, $params, $scheme, $siteId) - Generate site URL
url($path, $params, $scheme) - Generate URL
encodeUrl($url) - Encode URL for safe output
alias($alias) - Get Craft alias (e.g., @web, @root)
getenv_craft($name, $default) - Get environment variable
parseEnv($value) - Parse environment variable value
parseBooleanEnv($value) - Parse boolean environment variable
configure($object, $properties) - Configure object properties
create($config) - Create object from config array
clone_var($var) - Clone a variable (clone is reserved)
expression($expression, $params, $config) - Create database expression
entryType($handle) - Get entry type by handle
plugin($handle) - Get plugin instance by handle
collect($var) - Create collection (returns ElementCollection for elements)
shuffle_arr($arr) - Shuffle array randomly
fieldValueSql($provider, $fieldHandle, $key) - Get field value SQL
gql($query, $variables, $operationName) - Execute GraphQL query with full access
seq($name, $length, $next) - Get next or current sequence value
renderObjectTemplate($template, $object) - Render template with object context
raw($string) - Mark string as safe HTML
canCreateDrafts($element, $user) - Check if can create drafts
canDelete($element, $user) - Check if can delete element
canDeleteForSite($element, $user) - Check if can delete for site
canDuplicate($element, $user) - Check if can duplicate element
canSave($element, $user) - Check if can save element
canView($element, $user) - Check if can view element
actionInput($action, $params) - Generate hidden action input
csrfInput() - Generate CSRF token input
hiddenInput($name, $value, $options) - Generate hidden input
input($type, $name, $value, $options) - Generate input element
failMessageInput($message) - Generate fail message input
successMessageInput($message) - Generate success message input
redirectInput($url) - Generate redirect input
attr($attributes) - Render HTML attributes string
tag($type, $attributes) - Generate HTML tag
ol($items, $attributes) - Generate ordered list
ul($items, $attributes) - Generate unordered list
svg($svg, $sanitize, $namespace, $class) - Generate SVG element
head() - Register head content
beginBody() - Begin body event
endBody() - End body event
dump(...$vars) - Dump variables for debugging
__($message, $category, $params, $language) - Translate message
href="{{ siteUrl('blog') }}"
href="{{ cpUrl('entries') }}"
href="{{ actionUrl('users/logout') }}"
href="{{ url('about') }}"{{ alias('@web') }} {{-- Web root path --}}
{{ getenv_craft('APP_ENV', 'production') }}
{{ parseEnv('$APP_KEY') }}@php
$config = ['class' => 'MyClass', 'property' => 'value'];
$object = create($config);
$entryType = entryType('blog');
$myPlugin = plugin('my-plugin');
@endphp@php
$collection = collect($items); {{-- ElementCollection if all items are elements --}}
$shuffled = shuffle_arr($items);
@endphp@if (canView($entry))
{{-- Show entry --}}
@endif
@if (canDelete($entry))
<button>Delete</button>
@endif
@foreach ($entries as $entry)
@if (canEdit($entry))
<a href="{{ $entry.cpEditUrl }}">Edit</a>
@endif
@endforeach{{-- Form Inputs --}}
{{ csrfInput() }}
{{ hiddenInput('redirect', $redirect) }}
{{ actionInput('users/logout') }}
{{-- HTML Elements --}}
{{ tag('div', ['class' => 'container', 'html' => 'Content']) }}
{{ ol(['Item 1', 'Item 2', 'Item 3']) }}
{{ ul(['Item 1', 'Item 2', 'Item 3']) }}
{{ svg('/images/icon.svg', true) }}
{{ attr(['id' => 'my-id', 'class' => 'active']) }}{{ __('Hello, world!') }}
{{ __('Username', 'site', [], 'en') }}
{{ __('Error message', 'errors') }}{{ dump($variable) }}
{{ dump($var1, $var2, $var3) }}actionUrl(string $path = '', array $params = [], ?string $scheme = null): string
cpUrl(string $path = '', array $params = [], ?string $scheme = null): string
siteUrl(string $path = '', array $params = [], ?string $scheme = null, ?string $siteId = null): string
url(string $path = '', array $params = [], ?string $scheme = null): string
encodeUrl(string $url): stringalias(string $alias): string
getenv_craft(string $name, mixed $default = null): mixed
parseEnv(string $value): string
parseBooleanEnv(string $value): boolconfigure(object $object, array $properties): object
create(array|string $config): object
clone_var(mixed $var): mixed
expression(mixed $expression, array $params = [], array $config = []): Expression
entryType(string $handle): EntryType
plugin(string $handle): ?PluginInterfacecollect(mixed $var): Collection|ElementCollection
shuffle_arr(iterable $arr): array
fieldValueSql(FieldLayoutProviderInterface $provider, string $fieldHandle, ?string $key = null): ?stringgql(string $query, ?array $variables = null, ?string $operationName = null): arrayseq(string $name, ?int $length = null, bool $next = true): int|stringrenderObjectTemplate(string $template, mixed $object): string
raw(string $string): stringcanCreateDrafts(ElementInterface $element, ?User $user = null): bool
canDelete(ElementInterface $element, ?User $user = null): bool
canDeleteForSite(ElementInterface $element, ?User $user = null): bool
canDuplicate(ElementInterface $element, ?User $user = null): bool
canSave(ElementInterface $element, ?User $user = null): bool
canView(ElementInterface $element, ?User $user = null): boolactionInput(string $action, array $params = []): string
csrfInput(): string
hiddenInput(string $name, string $value = null, array $options = []): string
input(string $type, string $name = null, string $value = null, array $options = []): string
failMessageInput(string $message = null): string
successMessageInput(string $message = null): string
redirectInput(string $url): string
attr(array $attributes): string
tag(string $type, array $attributes = []): string
ol(array $items, array $attributes = []): string
ul(array $items, array $attributes = []): string
svg(Asset|string $svg, ?bool $sanitize = null, ?bool $namespace = null, ?string $class = null): stringhead(): void
beginBody(): void
endBody(): voiddump(...$vars): string__($message, $category = null, $params = null, ?string $language = null): string| Category | Count | Functions |
|---|---|---|
| URL & Navigation | 5 | actionUrl, cpUrl, siteUrl, url, encodeUrl |
| Configuration | 4 | alias, getenv_craft, parseEnv, parseBooleanEnv |
| Object & Creation | 6 | configure, create, clone_var, expression, entryType, plugin |
| Collections & Arrays | 3 | collect, shuffle_arr, fieldValueSql |
| GraphQL | 1 | gql |
| Sequences | 1 | seq |
| Template Rendering | 2 | renderObjectTemplate, raw |
| Authorization | 6 | canCreateDrafts, canDelete, canDeleteForSite, canDuplicate, canSave, canView |
| Form Inputs | 7 | actionInput, csrfInput, hiddenInput, input, failMessageInput, successMessageInput, redirectInput |
| HTML Elements | 5 | attr, tag, ol, ul, svg |
| DOM Events | 3 | head, beginBody, endBody |
| Debug | 1 | dump |
| Translation | 1 | __ |
| TOTAL | 45+ |
<form method="post" action="{{ actionUrl('posts/save') }}">
{{ csrfInput() }}
{{ hiddenInput('redirect', '/blog') }}
{{ input('text', 'title', '', ['class' => 'form-control']) }}
<button type="submit">Save</button>
</form>@foreach ($entries as $entry)
<div>
<h3>{{ $entry->title }}</h3>
@if (canView($entry))
<p>{{ $entry->description }}</p>
@endif
@if (canDelete($entry))
<a href="{{ actionUrl('entries/delete', {id: entry.id}) }}">Delete</a>
@endif
</div>
@endforeach@if (getenv_craft('APP_DEBUG'))
{{ dump($debugInfo) }}
@endif
Database: {{ getenv_craft('DB_DATABASE', 'craft') }}@php
$items = collect($entries);
$shuffled = collect($entries)->shuffle();
@endphp
@foreach ($items as $item)
{{-- Render item --}}
@endforeach{{ ol(['First item', 'Second item', 'Third item'], ['class' => 'custom-list']) }}
{{ ul($items->pluck('title')->all(), ['id' => 'nav']) }}<h1>{{ __('Welcome to our site') }}</h1>
<p>
{{ __('Hello, {name}!', 'site', ['name' => $user->name]) }}
</p>
<button>{{ __('Delete', 'buttons') }}</button>- User Context: Authorization functions (
canCreate,canDelete, etc.) can accept an optional user parameter. If omitted, the current user is used. - Aliases: Common aliases are
@web,@root,@basePath,@storage. See Craft documentation for complete list. - Collections: Use
collect()to create Illuminate collections, which has many helpful methods likemap(),filter(),pluck(), etc. - HTML Safety: Use
raw()to mark strings as safe HTML when they contain markup. - Forms: Always include
csrfInput()in forms. UsefailMessageInput()andsuccessMessageInput()with form redirects. - Translation: The
__()function defaults to 'site' category if not specified.
BLADE_FILTERS_QUICK_REFERENCE.md- Filter functionsHELPER_FUNCTIONS_MAPPING.md- Detailed helper function mappingREADME.md- Plugin overview