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
Related
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
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 want to write to a region in my template from the view and also from an included view thing the first view but no matter what I try it doesn't work. I have tried using #parent and #append but nothing has produced the result that I want so far.
In my layout I have the following:
#yield('scripts')
In my view primary I have the following:
#include('admin/rules/partials/_form')
#section('scripts)
// javascript #1 here
#stop
In admin/rules/partials/_form I have the following:
#section('scripts)
// javascript #2 here
#stop
So like I said I have tried using #parent after #section('scripts') and also using #append instead of #stop but nothing I do includes the two script blocks properly. The best I've had so far is javascript #1 being included once and javascript #2 being included twice. How would I do this so that each block of code is appended to the scripts region only once?
I solved it in the end I had to do the following:
#yield('scripts')
In my view primary I have the following:
#include('admin/rules/partials/_form')
#section('scripts')
// javascript #1 here
#stop
In admin/rules/partials/_form I have the following:
#section('scripts')
#parent
// javascript #2 here
#overwrite
This answer worked for me.
EDIT, but now it doesn't.
EDIT, I updated the code below to work. I was yielding the javascript section on the page and the layout.
tests.layout.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>
#yield('title') - test
</title>
#yield('head')
</head>
<body>
#yield('content')
#yield('javascript')
</body>
</html>
tests.page.blade.php
#extends('layouts.default')
#section('title', 'Poses')
#section('content')
<div class="container">
<div class="row">
#include('tests.partials.one')
#include('tests.partials.two')
</div>
</div>
#stop
tests.partials.one.blade.php
#section('content')
#parent
<h1>One</h1>
#stop
#section('javascript')
#parent
<script>Scripts from one</script>
#stop
tests.partials.two.blade.php
#section('content')
#parent
<h1>Two</h1>
#stop
#section('javascript')
#parent
<script>Scripts from two</script>
#stop
For further reference: http://laravel.com/docs/5.0/templates
In my case, I'm not set the section #stop. After using #stop, it works properly.
I have login.blade.php in views/users/ that I would like to exclude from the master layout that I have.
Instead I want the login page to be a standalone page with just the login form on it.
How may I achieve that?
Use a different layout for login page:
File app/views/login.blade.php:
#extends('layouts.standalone')
#section('content')
...
#stop
And for your other pages:
File app/views/home.blade.php:
#extends('layouts.master')
#section('content')
...
#stop
And here your layouts:
File app/views/layouts/standalone.blade.php:
<html>
<body>
This is a master layout
#yield('content')
</body>
</html>
File app/views/layouts/master.blade.php:
<html>
<body>
This is a standalone layout
#yield('content')
</body>
</html>
So,
I basically have a component which requires javascript to be loaded beforehand.
master layout:
//layouts/master.blade.php
...
#yield('scripts')
...
#include('forms.search')
...
my component:
//forms/search.blade.php
#section('scripts')
some scripts here
#stop
...
what Im calling:
//main.blade.php
#extends('layouts.master')
This does not work. Section is not added to header. Am I doing something wrong or it's not possible at all with laravel?
You are trying to yield the section before including. So try this.
In your //main.blade.php
#extends('layouts.master')
And in //layouts/master.blade.php
#include('forms.search')
And //forms/search.blade.php
some scripts here
you are calling
#extends('layouts.master')
which has a
#yield('scripts')
but you are declaring the section scripts on forms/search.blade.php
so if you examine correctly, you are declaring scripts on the wrong blade template OR you have put the yield area on the wrong blade template.. because since the #yield is on the layouts/master.blade.php, it had been executed already before the #include, which does not extend anything so declaring #section there wouldn't matter.
to achieve what you want, the
#section('scripts')
some scripts here
#stop
section should be in the main.blade.php file..
if i'm gonna do that, it would be something like this:
layouts/master.blade.php
<html>
<head>
<!-- more stuff here -->
#yield('scripts')
<!-- or put it in the footer if you like -->
</head>
<body>
#yield('search-form')
#yield('content')
</body>
</html>
forms/search.blade.php
//do whatever here
main.blade.php
#extends('layouts/master')
#section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
#stop
#section('search-form')
#include('forms/search')
#stop
OR remove the #yield('search-form') totally on master.blade.php and on main.blade.php do this:
#section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
#stop
#section('content')
#include('forms/search')
<!-- other stuff here -->
#stop
I was having the same problem, What got it working for me was adding "#parent" to ALL my sections...
{{-- Main area where you want to "yield" --}}
#section('js')
#show
#section('js')
#parent
{{-- Code Here --}}
#stop