Blade vs Twig Reference
If you've previously developed themes with the legacy Laminas/Twig system, this page is your translation guide. Everything you could do in Twig has a Blade equivalent.
Syntax Comparison
Printing Variables
Security
Always use {{ }} for user-generated content (auto-escapes HTML). Only use {!! !!} for trusted HTML from the database or known-safe helper functions.
Conditionals
Loops
Template Inheritance
Including Partials
Setting Variables
Object vs Array Access
In Twig, both objects and arrays use dot notation:
In Blade, arrays use ['key'] and objects use ->property:
{{-- Product from a helper like featureProducts() is an array --}}
{{ $product['name'] }}
{{-- $page->settings is an object --}}
{{ $page->settings->siteTitle }}
Filters → PHP Functions
Twig filters become PHP function calls in Blade:
| Twig Filter | Blade Equivalent |
|---|---|
\| upper |
{{ strtoupper($var) }} |
\| lower |
{{ strtolower($var) }} |
\| trim |
{{ trim($var) }} |
\| length |
{{ twig_length($var) }} or {{ count($var) }} |
\| date('Y-m-d') |
{{ twig_date($var, 'Y-m-d') }} |
\| default('fallback') |
{{ twig_default($var, 'fallback') }} or {{ $var ?? 'fallback' }} |
\| first |
{{ twig_first($var) }} |
\| raw |
{!! $var !!} |
Comment Syntax
Auth Checks
Helper Function Migration
| Twig Helper | Blade Equivalent |
|---|---|
featureProducts() |
featureProducts() ✅ same |
latestProducts() |
latestProducts() ✅ same |
seasonsBestProduct(n) |
seasonsBestProduct(n) ✅ same |
discountedProducts() |
discountedProducts() ✅ same |
visitedProducts(identity()) |
getVisitedProducts() |
MostviewedProducts() |
getVisitedProducts() |
hybridauthinfo(provider, serverUrl(true)) |
hybridAuth(route('user.login', [], false), 'provider') |
tagPrice(value) |
tagPrice($value) ✅ same |
tagShortText(text, len) |
tagShortText($text, $len) ✅ same |
tagDescription(text, len) |
tagShortText($text, $len) (unified) |
getAlt(image) |
getAlt($image, $fallback) |
serverUrl() |
serverUrl() ✅ same |
getPath(themes.image) |
getPath($themes->image) |
bulkBuyer() |
bulkBuyer() ✅ same |
identity() |
identity() ✅ same |
getCart('cartProductQuantity') |
getCart('cartProductQuantity') ✅ same |
url('user/login') |
route('user.login', [], false) or customUrl('login') |
dumpVar() |
{{ dump($variable) }} or @dump($variable) |