on my main.blade.php
<div class="container">
#yield('content')
</div>
on my home.blade.php
#extends('main')
#section('content')
<div class="row">
<h1>this content should show on my main</h1>
</div>
#endsection
what could be wrong it's not displaying the content on my #section i have no errors but it's not working by the way I'm using Laravel 5.4
Make sure your main.blade.php and home.blade.php lies in
resource/views/
If they lie in different directory use " . " to specify directory
For example, if main.blade.php is in resource/views/layouts then it would be something like this #extends('layouts.main')
I think you need to update your code for main.blade.php like:
<div class="container">
#yield('content')
</div>
To
<section class="content">
#yield('content')
</section>
Hope this work for you
Related
in a Laravel project I want to add a section inside another section I've tried with a #yield but didn't worked.
and now I have this code:
#section('form')
<form>MY FORM</form>
#endsection
and I put it inside this:
#extends('layouts.app')
#section('content')
<body class: my page
#include('form')
</body>
#endsection
but when it loads I only see what 'content' has but not the #include() part.
You don't need to put #section('form') on your form.blade.php . Here's a simple example:
//index.blade.php
#extends('layouts.app')
#section('content')
<body class="my-page">
#include('form')
</body>
#endsection
On the Form element
<form>MY FORM</form>
If you do this, here's what output will look like:
<body class="my-page">
<form>MY FORM</form>
</body>
#extends('layouts.app')
#section('content')
<body class: my page
#yield('form')
</body>
#endsection
In Form Blade
#extends('index')
#section('form')
#parent
<form>MY FORM</form>
#endsection
Try like this
Extending layouts and dividing a view file into sections, wherein "x" section goes inside "x" section of the layout when rendering. Like it's done in blade using #extend() and #section() []. I just want to implement this on my own PHP without using any library or framework. This is how blade does it :
Layout File [app.blade.php]
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
View File [my-page.blade.php]
#extends('layouts.app')
#section('title', 'Page Title')
#section('sidebar')
<p>This is appended to the master sidebar.</p>
#endsection
#section('content')
<p>This is my body content.</p>
#endsection
When trying to use #yield and #section it does not work. With only extending the layout, all the layout is rendered, I can't choose with #section and #endsection what will be rendered.
This is for a Laravel project with HomeStead on my local machine
plantilla.blade.php is:
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
<div>
#yield('sidebar')
This is the master sidebar.
</div>
<div class="container">
#yield('content')
This is another container
</div>
</body>
</html>
And the contact.blade.php is:
#extends("layouts.plantilla")
#section('content')
#endsection
When opening contact.blade.php, both sections are displayed (sidebar AND content), instead of only content, which is the section I'm actually calling.
This happens also if I just leave the first line (#extends("layouts.plantilla")
without calling any section, it will render all of its content
What could am I doing wrong here?
That's because you are yielding both content and sidebar inside your div already, so the "This is the master sidebar" and "This is another container" will always show, even if you don't use that section.
You need to change your code in main layout like this:
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
#yield('sidebar')
#yield('content')
</body>
</html>
So now, if you only want to display a content of your page, you do it like this:
#extends("layouts.plantilla")
#section('content')
<div class="container">
This is another container
</div>
#endsection
I have this code:
in laravel/resources/views/users.blade.php
#extends('layouts.main')
#section('content')
<p>
Here's your content
</p>
#stop
in laravel/resources/views/layouts/main.blade.php
<html>
<head>
{{-- Common Header Stuff Here --}}
</head>
<body>
<div class="navigation">
#section('navigation')
Home
Contact
#show
</div>
<div class="container">
#yield('content')
</div>
in routes.php
Route::get('users', function()
{
return View::make('users');
});
When i launch my site (localhost/laravel/public/users) It prints only:
#extends('layouts.main')
what's wrong here? I'm using laravel 5
Thanks in advance, i'm newbie with laravel
FIIIIIIIIXEEED
#extends can't be indented, you can't put anything before it even whitespace.
I think in Laravel 5 you cannot use return View::make('users'); That's only for pure HTML content (already compiled). If you want to use blade templates, you should instead use :
return view('users');
I a'm trying to yield my content from controllers. But I don't want to define again and again that I want to yield the 'Content' section
How can I archive this, so I don't need to place
#section('body')
<h1>Content</h1>
<p>More content</p>
#stop
again is every view
For example, ASP.NET MVC with RenderBody()
Use Blade templating engin, create a master layout in your `app/views/layouts' folder something like this template:
<!-- master.blade.php -->
<html>
<head></head>
<body>
<div class="container">
#yield('content')
</div>
</body>
</html>
Then in your every child view, just extend the master view, for example:
<!-- home.blade.php -->
#extends('layouts.master')
#section('body')
<h1>Content</h1>
<p>More content</p>
#stop
So, whenever you'll use something like this:
return View::make('home');
Your child view will extend the master view and content will be yielded inside the div.container.