Dwight Watson's blog

Laravel 4.1 Blade "if isset" shorthand

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

Laravel 4.1 introduces a new shorthand for echoing out data in Blade, which is really nice.

{{ $variable or 'default' }}

This shorthand actually expands out to a full isset call on the variable and returns the default value if false.

isset($variable) ? $variable : 'default'

So if you're not sure if something is going to appear in the view or not, here's a nice way to test!

A blog about Laravel & Rails by Dwight Watson;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.