Template InheritanceMaster Page LayoutMaster page layout defines the common layout across all the web pages. All the web applications have the master page layout to define the common layout across all the web pages. The blade templating engine defines the master layout that can be extended by all the web pages. The master page layout is available in the /resources/views/layouts/ directory. Let's understand through an example.
master.blade.php In the above code, we have used the @yield directive. The @yield is used to display the content. The @yield('content') displays the content of the 'content' while @yield('footer') displays the content of the footer. Extending Master Layout
Contact.blade.php In the above code, we use the @extends directive. The '@extends' directive is used to inherit the blade layout in contact.blade.php file. The '@section('content')' defines the section of the content.
Output We can also add the javascript code in contact.blade.php file. Suppose I added the following code in contact.blade.php file. In the above code, I created the alert box, which is displaying the message "Hello JavaTpoint". Output Let's see another example of blade template.
post.blade.php The above code defines the section of the content in which we are displaying the values of id, password and name respectively.
PostController.php In PostController.php file, we defined a new function named as show_post() which passes the data to the post.blade.php file.
web.php Output Till now, we have seen that both the post.blade.php and contact.blade.php files are extending the master layout file. This is the main advantage of a master layout that every file can extend the layout of the master file and add their own functionalities. Use of @parent directiveThe use of @parent directive is to display the content of the section defined in the master layout. Let's understand through an example.
master.blade.php
In the above code, @parent directive adds the paragraph content to the footer section. Output
Next TopicLaravel Forms
|