Support the ongoing development of →
Views Blade
Last updated 2 years ago.

Never thought about it like that actually, very useful :) Thanks for sharing!

Last updated 2 years ago.

I'd like to add my thoughts on this as I do similar thing but with bit more flexible way, and you will also find this is useful when it comes to web sites with many pages of different context.

I use @yield only to output content dynamically, more specifically for the content which always change, and if we know something is used all the time or majority of time I use include. I'll explain it in more detail below.

Another reason for my structure is to totally main javascripts and css references into different files, so that I can easily find them and my master layout page only contain the contents. I can also reuse css and scripts in different master files as well. Then we have scripts/css common to all (ex: bootstrap) and there are some specific to pages . by following way we can use them properly only when needed.

master.blade.php (This is the layout file inside view/layout)

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Web Site</title>


    <div class="container" id="main">

    </div><!-- #main -->



as you can see we have included two files one for css and one for scripts

style.blade.php (where we define common .css)

{{ HTML::style('packages/bs/css/bootstrap.min.css') }}

{{ HTML::style('css/style.css') }}


Note that we have defined the common css files there but also given option to include any new css files by child pages if required on their own pages by defining a section called 'styles'

script.blade.php (main javascript file page)

<script src=""></script>

{{ HTML::script('packages/bs/js/bootstrap.min.js') }}


similar to css here we have defined 'scripts' section so sub views can define their own section.

(child view)


{{ HTML::style('css/style2.css') }}

{{ HTML::script('js/app.js') }}

<div class="col-12">
    This is the content

As you can see we have included new styles and js which required only in this child view here, so that they won't appear all the time as when we define all scripts in master page.

P.S. As I remember Laravel 3 had tag which we can use to control where should parent view section appear from our child view. I'm not sure they still support it. If it is then we can have more control over precedence of scripts and styles.

Last updated 2 years ago.

The OP is actually what I believed to be the intended use of sections and yields and is how I've always used them. technet's post is very clever, and a really neat way to manage page specific scripts and styles, love it.

Last updated 2 years ago.

How do you not include a section from the default page in my code the page header has a navbar I do not include in another page but am wondering how not to include it in my other pages .


This is a game changer. Thank you so much. Jose-L.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.