Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is this a correct way to arrange a layout file?

I have one single layout file.

Is this a correct way to design it:

<html>
<head>
    <meta ...>
    <meta ...>
    <meta ...>
    
    <title> some title </title>

    <link href=" ... " rel="stylesheet">
    <link href=" ... " rel="stylesheet">
    <link href=" ... " rel="stylesheet">
    <link href=" ... " rel="stylesheet">
</head>
<body>

    <main>
        @yield('content')
    </main>
   
    <script src=" ... "></script>
    <script src=" ... " ></script>
    <script src=" ... " ></script>
    <script src=" ... "></script>

    @stack('scripts')
</body>
</html>

The way I placed the CSS on top, JS at the bottom of the body, under content and above the stack. Is this an ok way? Or I should have used some directives for that?

Ty

0 likes
8 replies
Tray2's avatar

Yeah it looks like a good way to do it. You know that you can yield the title as well so that you can ave dynamic titles depending on what page you are displaying.

1 like
Ligonsker's avatar

@Tray2 yes! It's actually dynamic I just kept the overall structure.

Also I forgot to create styles stack:

@stack('styles')

Should that go below the rest of the styles?

Anything else I may have forgotten?

kokoshneta's avatar

@Ligonsker That depends on what your other styles are. If there are any rules that exist in both the individually loaded styles and your stack styles, putting the stack first means you allow the individually loaded styles to override your styles; putting it last means your stack styles override the individually loaded styles.

1 like
Ligonsker's avatar

@kokoshneta oh haha my bad, I put it at the bottom because I thought the last file has more priority. Now I learned that it should be on top to get more priority, thank you

kokoshneta's avatar

@Ligonsker No no, you were right the first time. In CSS, later definitions will override earlier ones. So when you put your stack last, you give that priority, and it will override any identical rules in your order styles. If you want the other styles to be able to override your stack styles, you should put the stack first.

1 like
Ligonsker's avatar

@kokoshneta I just came back say that as well as I went to check again, thank you. I will leave it at the bottom then

Akash_kushwaha's avatar

It's good. But try Including Header ,footer and script files separately for batter understanding.

1 like
Ligonsker's avatar

@Akash_kushwaha what do you mean? Can you please provide an example? Even if these are global styles such as bootstrap I should still change it?

Please or to participate in this conversation.