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' />
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:
sidebar.blade.php
to include?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:
preg_*
./app/views/temp/whatever.tmp.blade.php
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.)
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community