Laravel blade templates error - php

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');

Related

how do i add a section inside a section in Laravel

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

Laravel blade #yield and #section

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

Laravel template showing two blade templates from route

I have a full html template, that I am trying to use with laravel.
The template has a big image slider (that should only be in homepage) and a couple of other codes like contact form, accordion, twitter widget... my goal is to place those parts in separate blade templates and call them when needed. For this, I have this folder scheme.
..
/views
/emails
/home
- slider.blade.php
- contact-form.blade.php
- twitterwidget.blade.php
/layouts
- master.blade.php
So, for example master.blade.php looks like this.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class='header'>
//header
#yield('slider')
</div>
<div class='content'>
//content
#yield('contact-form')
</div>
<div class='footer'>
//footer
</div>
</body>
</html>
Now that is a basic examples which yields a slider inside the headers tags, and this is the slider.blade.php:
#extends('layouts.master')
#section('details')
<div class='slider'> I am a slider </div>
#stop
but when I create a route, I am forced to create one point to one template. as:
Route::get('/', function(){
return View::make('home/slider');
});
This only renders the layout by pulling the slider. But I want to contact form to be rendered also.
In master.blade.php file instead of
#yield('contact-form')
you should use:
#include('home.contact-form')
or you can edit your slider.blade.php file and add at the end:
#section('contact-form')
#include('home.contact-form')
#stop

Laravel once defind yield content

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.

How to modify layout sections from included views in laravel 4?

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

Categories