Any PHP expression within double curly braces {{ $variable }}
will be echo
ed after being run through the e
helper function. (So html special characters (<
, >
, "
, '
, &
) are safely replaced for the corresponding html entities.)
(The PHP expression must evaluate to string, otherwise an exception will be thrown.)
{{ $variable }}
{{ $array["key"] }}
{{ $object->property }}
{{ strtolower($variable) }}
Normally, in PHP, to check if a variable is set and print it you would do
<?php echo isset($variable) ? $variable : 'Default'; ?>
<?php echo $variable ?? 'Default'; ?>
Blade operator or
makes this easier:
{{ $variable or 'Default' }}
As mentioned, regular double braces syntax {{ }}
, are filtered through PHP's htmlspecialchars
function, for security (preventing malicious injection of HTML in the view). If you would like to bypass this behavior, for example if you're trying to output a block of HTML content resulting from a PHP expression, use the following syntax:
{!! $myHtmlString !!}
Note that it is considered a best practice to use the standard {{ }}
syntax to escape your data, unless absolutely necessary. In addition, when echoing untrusted content (ie. content supplied by users of your site), you should avoid using the {!! !!}
syntax.