Using new feature of 4.1 to output a default string

Submitted by msurguy - 9 years ago

Previously, if you wanted to output a default value of a string in Blade you would put a condition that checks if the variable is set, otherwise defaults to some value. Now you can shorten the code by using the keyword "or" to specify what should be displayed if the variable is not set.

// In Laravel 4.0:
{{ isset($seo->title) ? $seo->title : 'Viewing Category' }}

// In Laravel 4.1:
{{ $seo->title or 'Viewing Category' }}