Create page with Blade Template Engine in Laravel

Laravel present easy and very strong templating engine. This templating engine connects one or more templates which are made by inheritance and part to produce required views page.

Blade template has its own control construction like loops and conditional statements. Inheritance and Section are main benefits of using Blade template engine.

To make Blade format, essentially make your view document with .blade.php extension rather than .php and it is regularly saved in the resources/views folder.

Want to learn Laravel installation instruction here

Step 1: Prepare Layout Page
All blade files must be saved with the .blade.php extension. In this segment, we will make a page layout that all pages will use it. The following code for defining a page layout.

  1. create new folder my_layouts in /resources/views/
  2. create a new file layout.blade.php in /resources/views/my_layouts/layout.blade.php
  3. add the following code to layout.blade.php
  • @yield(‘page_title’) is used to veiw the value of the page title
  • @section(‘page_menu’) is used to define a section named page menu
  • @show is used to display the html contents of a section
  • @yield(‘page_content’) is used to view the main page contents details

Step 2:  Utilizing layout page to create a display page with content. Following code use to create a page with original content using our layout and save it as tasks.blade.php. Here @extends(use to include the layout page with this page and @section and @endsection key use to define a what kind of content going to display into the page. {{ }} double opening curly braces and double closing curly braces are used to display the value of the variable.

Step 3:  Define a route for the page in routes.php. Here we can declare and define a variable and array with a value for the page required details. compact() method use to attach the variable with view page.

Final output as,

Creating your first Laravel Application

Learn Infinity

Learn Infinity is the most famous Programming & Web Development blog. Our principal is to provide the best online tutorial on web development. We execute the best tutorials for web experts this will help developers, programmers, freelancers and proving free resource you can download or preview the tutorials.

Leave a Reply

Your email address will not be published.

Back to top