banner



How To Create A Blade Template In Laravel

Layouts are oft the starting betoken of many spider web evolution projects. Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes.

All views in Laravel are ordinarily built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified. All the files in resource/views have the extension .blade.php.

Laravel blade template is pretty impressive in operation.  This tutorial will serve as an introduction to this templating engine.

Note: For the purpose of this tutorial, you will need a fresh installation of Laravel project.

Create Pages Routes

Get-go, I will create the routes to gain access to my folio. Open routes/spider web.php and add the following lines in it.

Route::get('/', function()  {     return View::make('pages.home');  });  Road::go('/about', function()  {     render View::make('pages.contact');  });        

Stop Wasting Time on Servers

Cloudways handle server management for you so you can focus on creating neat apps and keeping your clients happy.

We are only working on views only, and thus don't need to access the controllers.  To learn more about controllers, take a wait at: Working With Controllers And Middleware

Create Views Construction

At present that the routes are ready, allow'south create the Views structure past creating the following folders and files.

- resources  -- views  --- layouts  ------- default.blade.php  --- pages  ------- home.blade.php  ------- contact.bract.php  --- includes  ------- caput.bract.php  ------- header.blade.php  ------- footer.bract.php

Create Includes

Create the post-obit includes, with the following code:

head.blade.php

<meta charset="utf-viii">  <meta proper name="description" content="">  <meta name="Saquib" content="Bract">  <title>Checkout our layout</title>  <!-- load bootstrap from a cdn -->  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/3.0.3/css/bootstrap-combined.min.css">        

Header.blade.php

<div class="navbar">     <div class="navbar-inner">         <a id="logo" href="/">Single Malt</a>         <ul class="nav">             <li><a href="/">Habitation</a></li>             <li><a href="/contact">Contact</a></li>         </ul>     </div>  </div>

footer.bract.php

<div id="copyright text-right">© Copyright 2017 Saquib Rizwan </div>

Create the Layout

I volition use @include to bring in tiny parts of the code that I have created in includes folders, and @yield to bring in content from the individual pages I will be using.

<!doctype html>  <html>  <caput>     @include('includes.head')  </head>  <trunk>  <div class="container">     <header class="row">         @include('includes.header')     </header>     <div id="chief" class="row">             @yield('content')     </div>     <footer class="row">         @include('includes.footer')     </footer>  </div>  </body>  </html>        

Blade allows the use of the layout that I merely created past using @extends. By creating @section, I will create a section that will be used in the layout. Here I volition use @department('content') and in the layout, everything that I volition blazon hither will be injected in @yield in the layout.

Get to resource/views/pages and put the post-obit code in these files.

pages/habitation.blade.php

@extends('layouts.default')  @section('content')     i am the home page  @stop

pages/contact.blade.php

@extends('layouts.default')  @department('content')     i am the contact page  @stop

Conclusion

This is the unproblematic foundation and the basic steps for getting starting with Blade templating engine. Now that yous know the file structures and the way Laravel Blade template engine renders the view, I will demonstrate how to integrate Bootstrap template with Laravel in my next article. So stay tuned.

Share your opinion in the comment section. COMMENT At present

Share This Article

Customer Review at

"Cloudways hosting has one of the best client service and hosting speed"

Sanjit C [Website Developer]

Saquib Rizwan

Saquib is a PHP Community Expert at Cloudways - A Managed PHP Hosting Cloud Platform. He is well versed in PHP and regularly contributes to open up source projects. For fun, he enjoys gaming, movies and hanging out with friends. You can email him at [email protected]

×

Get Our Newsletter
Exist the commencement to go the latest updates and tutorials.

Thankyou for Subscribing Us!

How To Create A Blade Template In Laravel,

Source: https://www.cloudways.com/blog/create-laravel-blade-layout/

Posted by: childresswalbra1935.blogspot.com

0 Response to "How To Create A Blade Template In Laravel"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel