11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Blade<br />

In this chapter, we will learn how to master the Blade. You will need it. In order to claim your rightful<br />

place as a PHP artisan you will need to challenge and defeat High Lord Otwell in armed combat.<br />

It’s a rite of passage. Only then will you be able to take your rightful place amongst the Laravel<br />

council, and earn a spot at Phil Sturgeon’s drinking table.<br />

Once a month, us Council members ride out to the PHP battleground sat atop our fearsome Laravel<br />

riding pandas, to do battle with the developers of other frameworks. If you want to ride into battle<br />

alongside us, and fight for the honour of Laravel you must learn to master the Blade.<br />

Well, must is a strong word I suppose. I mean, you could also master Blade templating. It’s not<br />

quite as extravagant, and there are no fierce riding pandas involved. It is pretty handy though, and<br />

perhaps more suited to coder types than hardcore battle?<br />

Yeah that’s settled then, let’s have a look at Blade templating.<br />

You might be wondering about the name ‘Blade’? Well so was I as I wrote this chapter, so I decided to<br />

ask Taylor. It turns out that the .NET web development platform has a templating tool called ‘Razor’,<br />

from which much of the Blade syntax was derived. Razor..blade.. razorblade. That’s it. Nothing funny<br />

there really, sorry. :(<br />

Actually forget what I just told you, let’s reinvent that story. Just between us. The templating<br />

language was named after Taylor’s alter ego ‘Blade’ back during his days of Vampire hunting. That’s<br />

the real story.<br />

Right, let’s make a template.<br />

Creating Templates<br />

I know, I know, I already taught you how to create views right? They are really useful for separating<br />

the visual aspect of your application from its logic, but, it doesn’t mean they can’t be improved upon.<br />

The problem with standard PHP templates is that we have to insert those ugly PHP tags within them<br />

to use the data that our logic portions have provided. They look out of place within our neat HTML<br />

templates. They soil them! It makes me so angry… I could… I could. No, let me be for a moment.<br />

Erm…<br />

It’s ok, my rage has settled now. Let’s create a Blade template to get that nasty PHP mess out of the<br />

way. To get started we will need to make a new file. Blade templates live in the same location as our

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!