Now that we have some information in our database, we need to define the templates that are going to display it. Blade is Laravel's lightweight template language and its syntax is very easy to learn. Here are some examples of how Blade can reduce the number of keystrokes and increase the readability of your templates:
Standard PHP syntax |
Blade syntax |
---|---|
<?php echo $var; ?>
|
{!! $var !!}
|
<?php echo htmlentities($var); ?>
|
{{ $var }}
|
<?php if ($cond): ?>…<?php endif; ?>
|
@if ($cond) … @endif
|
If you use the default double braces notation, then variables are escaped. This is to protect against XSS vulnerabilities (explained in more detail in Chapter 7, Authentication and Security). If you really need the raw value of variable un-escaped, then you can use single braces, with two exclamation marks inside on each side. You should only do this if you trust the value that the variable contains.
Blade also supports all of PHP's major constructs to...