Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. Defining A Layout
  2.  
  3. Two of the primary benefits of using Blade are template inheritance and sections. To get started, let's take a look at a simple example. First, we will examine a "master" page layout. Since most web applications maintain the same general layout across various pages, it's convenient to define this layout as a single Blade view:
  4.  
  5. <!-- Stored in resources/views/layouts/app.blade.php -->
  6.  
  7. <html>
  8. <head>
  9. <title>App Name - @yield('title')</title>
  10. </head>
  11. <body>
  12. @section('sidebar')
  13. This is the master sidebar.
  14. @show
  15.  
  16. <div class="container">
  17. @yield('content')
  18. </div>
  19. </body>
  20. </html>
  21.  
  22. As you can see, this file contains typical HTML mark-up. However, take note of the @section and @yield directives. The @section directive, as the name implies, defines a section of content, while the @yield directive is used to display the contents of a given section.
  23.  
  24. Now that we have defined a layout for our application, let's define a child page that inherits the layout.
  25.  
  26. Extending A Layout
  27.  
  28. When defining a child view, use the Blade @extends directive to specify which layout the child view should "inherit". Views which extend a Blade layout may inject content into the layout's sections using @section directives. Remember, as seen in the example above, the contents of these sections will be displayed in the layout using @yield:
  29.  
  30. <!-- Stored in resources/views/child.blade.php -->
  31.  
  32. @extends('layouts.app')
  33.  
  34. @section('title', 'Page Title')
  35.  
  36. @section('sidebar')
  37. @parent
  38.  
  39. <p>This is appended to the master sidebar.</p>
  40. @endsection
  41.  
  42. @section('content')
  43. <p>This is my body content.</p>
  44. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement