Question

As I understand, Blade is simply regex parser, which will translate any Blade construction into PHP code, and then generate plain HTML from that PHP. Seems like this process makes loading files with Blade templates slower (because of the extra step Blade -> PHP). If so, why do I want to use Blade at all? Just because of the elegant syntax or because Blade files are stored in cache?

Was it helpful?

Solution

You'd use Blade because you want to use Blade. Like you've said it has a much nicer syntax and once you know its simple syntax it's very quick to use.

Regular PHP:

<?php if ($user->isLogged()): ?>
    Welcome back, <strong><?= $user->name; ?></strong>
<?php endif; ?>

Blade:

@if ($user->isLogged())
    Welcome back, <strong>{{ $user->name }}</strong>
@endif

Of course that's just a basic control structure. Blade has built in templating support as well.

Speed

There should be virtually no speed difference between the two as on the first load Laravel will compile any views that have changed into their PHP equivalent. Subsequent page loads will use this compiled file instead (they are stored at app/storage/views).

I guess the only extra overhead would be the initial check to see if the view has been compiled yet. Bugger all though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top