Inside the endsection no need anything. just @endsection. and use like this
<div>@yield ('header')</div>
@yield is not working
on my main.blade.php
@yield('header')
on my home.blade.php
@section('header')
<header class="masthead" style="background-image: url('template/img/home-bg.jpg')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Clean Blog</h1>
<span class="subheading">A Blog Theme by Start Bootstrap</span>
</div>
</div>
</div>
</div>
</header>
@endsection
what could be wrong?
Have you tried between div.
u mean like this "'@yield('header')'"
I have mentioned in first comment.
@MUNAZZIL - I've tried this
<div>
@yield('header')
</div>
still not displaying the header on my main.blade.php
Please change a name and check becuse header is common name. example head1
its on my views folder as well as my main.blade.php
What you have should work. main.blade.php and home.blade.php are in the same folder? In /views/? No subfolder?
yes my main.blade.php and my home.blade.php is both on my views folder no subfolder
So you have something like this in your home.blade.php:
@extends('main')
@section('header')
Bla bla
@endsection
And your route is returning the home view?
@RONB1985 - yes i did that on my home.blade.php but when i run checked the sour file its blank
Try removing the <header class= and so on, and just put some text in between:
@section('header')
This is my header
@endsection
See if that works at all. I suspect it's got something to do with that header html code
on my
@section('header')
<p>this is my header</p>
@endsection
The this is my header paragraph is not showing as well
Hmm strange.. Perhaps your views are cached or something? Just to try..
php artisan cache:clear
php artisan view:clear
You are checking the page source, not visually what it looks like?
so, just to check where we are;
main.blade.php contains layout and a @yield('section_name'). Also main.blade.php does not have @extends
Next, home.blade.php contains @extends('main') and @section('section_name') followed by @endsection
and both files are in the root of your resources\views folder?
and all filenames and references are in lowercase?
Section, yield, etc are convenience methods added, you could just skip and get straight to the point on what you need to include as example:
<?= View::make('partials/dpag')->render(); ?>
I can pop such as this in a template or view, doesn't matter.
No messing with section end section, yield, etc.
Just use your blade if so desired. Dig into the API to find out more.
I do not know why it does not work for you. but in my projects for the pieces of code I use a simple include
because for the components you do not simply use in home.blade.php:
@include('header')
and in the header.blade.php file, put:
<header class = "masthead" style = "background-image: url ('template / img / home-bg.jpg')">
<div class = "overlay"> </ div>
<div class = "container">
<div class = "row">
<div class = "col-lg-8 col-md-10 mx-auto">
<div class = "site-heading">
<h1> Clean Blog </ h1>
<span class = "subheading"> A Blog Theme by Start Bootstrap </ span>
</ Div>
</ Div>
</ Div>
</ Div>
</ Header>
@jlrdw why woukd you mess about with that bx when yield and section work perfectly?
Because
<?= View::make('partials/dpag')->render(); ?>
Is same thing but so much easier.
Also:
$view = 'dog/index';
$layout = ViewLayout::getLayout('dog/indextp'); //custom code
$content = View::make($view)
->with('dogs', $dogs);
return view($layout)->with('content', $content)->with('title', $title);
So return layout, not view and in layout:
<?php echo $content; ?>
content is the view. Make first in controller.
That is so much easier than yield, section, or whatever.
Besides if section, yield, etc was so easy, why so many questions on it here.
And with all due respect:
that bx
came from Taylor's API documentation.
I never checked prior, but from vendor folder:
$echo = "<?php echo $__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
You are just rendering whatever.
@jlrdw Ok, but OP was asking specifically about blade templates, so it would be best to actually help with that, if you're going to help, rather than give an answer the OP wasn't asking for. Most people here want to use laravel, and learn laravel. It doesn't really help much to answer a question that wasn't asked.
It's cool if you don't really know how to use blade and avoid it. No sweat, but most others don't want to do that. You really should actually learn it someday. You don't know what you're missing.
@lestah Please show your complete main.blade.php and home.blade.php files. Not some of the content, all of it.
But it's php. See example from vendor folder. I just do that direct. It is the exact same thing, you are rendering something at a certain place in the template.
It would be easier not to have yield, section, and just render what's needed where needed.
It does not hurt for folks to learn some things from the API, that's actually easier.
In fact unless you have an entire HTML page for the view, the flow should be:
- return layout
- in layout render whatever and the main view, via
<?= $content; ?>
Or the blade equal I guess:
{{ $content }} is that correct.
I am not trying to talk mean here, but some of the blade files asked here on forum look like old basic spaghetti code, not clean at all. Whereas just rendering what's needed makes for cleaner code.
I'm not saying don't use blade, I'm saying there is no need for section, and yield.
Still, that's not what the OP asked regardless if you think it's better or not.
@cronix that's true, I agree. But if OP ask for a piece of fish, may as well teach how to fish at same time.
Thats so funny
I don't think that analogy is applicable here. Should we expect a php dissertation whenever someone asks specifically about laravel stuff because it's all php behind the scenes? I assume they know php (how to fish) if they are using laravel. Now they want to use a net and be more efficient, so it's a step backwards and wastes time to teach them how to fish (again) when they are wanting (and asking for) the next step.
@cronix I am not trying to argue here but what you said is 180 degrees off. Look at what happens in the vendor folder, that is truly the net.
Not those shortcuts. It's the shortcuts many times that fumble up newcomers to the framework.
Instead of a direct approach to what's really happening in the background.
Furthermore as I said I am not saying don't use blade I'm just saying you can render direct, it's less code and a heck of a lot easier.
Please or to participate in this conversation.