Support the ongoing development of Laravel.io →
posted 10 years ago
Views Blade

I am new to blade and new to this forum. Before I create this thread, I have searched "only include", "include only", "1 section", and nothing interesting found.

The reason I do this is "I need to keep every template visible". I really want to see them, look at their styles.

Imagine there is a header.blade.php, which includes

<link ... href="bootstrap.css" />
<script src='jquery.js' />
<script src='bootstrap.js' />

And thre is a footer.blade.php

<html> <head> 
@include('header')
</head>
<body>
@section('footer')
<div> <div> <div> .... </div> </div> </div>
@show
</body>
</html>

And If there is a layout.blade.php, which also includes footer.blade.php, everything goes wrong.

<html> <head> 
@include('header')
</head>
<body>
@include('footer')
</body>
</html>

Here's the reason why some solutions are not working:

  • @extends This is not working because: What if there is another sidebar.blade.php to include?
  • Just make footer contain only thing you need to be included Then should I suppose to make another view to see what footer looks like? So does siderbar? So does login control? So does banner ? I don't think it is a good idea.

I also know it is nearly impossible because your compileInclude function just lets environment to compile target template without any parsing. And only compileExtends function does.

So, I have a solution now, but I know it is not good enough:

  • First, extend blade with a new function.
  • Second, inside the function, cut the target section code stupidly by preg_*.
  • Third, cache that section to /app/views/temp/whatever.tmp.blade.php
  • Finally, let enviroment to go for that file.

Also, I am really interested in this topic, and if I am allowed, I would like to contribute my code to this. (Maybe we can use Cache instead of raw files.)

Last updated 2 years ago.
0

Why nobody answering me.... Is that my english very poor?

0

You can create sections in your other blade files and inject them from another.

For example, you header can have an

@section('header')
@show

footer.blade.php

@section('footer')
@show

Then in your main body section you can use

@section('header')
IM INJECTING THIS INTO HEADER.BLADE.PHP
@stop
@section('footer')
IM INJECTING THIS INTO FOOTER.BLADE.PHP
@stop

Is that a solution? The code above replaces what is already in that section but you can just append stuff to the original content in that section.

0

adamkearsley said:

You can create sections in your other blade files and inject them from another.

For example, you header can have an

@section('header')
@show

footer.blade.php

@section('footer')
@show

Then in your main body section you can use

@section('header')
IM INJECTING THIS INTO HEADER.BLADE.PHP
@stop
@section('footer')
IM INJECTING THIS INTO FOOTER.BLADE.PHP
@stop

Is that a solution? The code above replaces what is already in that section but you can just append stuff to the original content in that section.

That is not a solution... What was outputed is quite different from expected.

Well, I have just implemented the solution... I will paste my code here.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

kcauchy kcauchy Joined 26 Jan 2015

Moderators

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

Your logo here?

Laravel.io

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

© 2025 Laravel.io - All rights reserved.