Laravel Blade template

Laravel Blade Template

Template:

As we all know what is templating. We use a template structure in our any type of site like divide layout in footer, header, sidebar called layout or templating.

Laravel Blade Template:

In this article we learn about How to create layout in laravel using blade templating.Blade is a simple, easy and wonderful template engine which is built in with laravel.

Instead of using controller layouts laravel blade template is an easy way to define inheritance and sections for layout. In laravel blade template we need to create each view file with .blade.php extension.
For example if you are going to creating a “phpclicks.php” file using laravel blade template then file name will be “phpclicks.blade.php”.

The General File Structure for Views:

Let’s create some necessary files for creating a whole template system. Following are the folders and files structure.

Note: In laravel 4 and Laravel 5 there is a slight difference in location for view directory.
In laravel4:
Project-directory/app/views

In Laravel5:
Project-directory/resources/views
Now we should move ahead and create them.

Views:

Now inside views root create further directories according to your requirement. We are creating folders as “layout” , ”includes” ,”pages” etc.
Layout:
Now inside the layout folder, create a template file like “layouts/myTemplate.blade.php”
Code for myTemplate.blade.php looks like as:

Includes:

Create a includes folder inside views directory and create common files like head , header , footer , sidebar etc so that we don’t have to rewrite that code. such as:
Views / includes / head.blade.php
Views / includes / header.blade.php
Views / includes / sidebar.blade.php
Views / includes / footer.blade.php
Code for head.blade.php:

Code for header.blade.php:

Code for sidebar.blade.php:

Code for footer.blade.php:

Pages:

Now create the files for inner content like SignUp or sign in ,about ,home .We are going to develop a sign in form. Create the page directory and create files for sign in.
Views / pages / signin.blade.php
Code for signin.php:

Routing:

Routing is an easy and efficient way to setup a simple route to get our pages.Open “app/Http/routes.php” and set the below path.

Run the below url to view the sign-in page
http://localhost:8000/sign-in