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>
Related
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
With Blade it seems the yield does not work with included parts. How can I fill a section defined inside an included part in the parent template?
It seems this is a known issue:
https://github.com/laravel/framework/issues/8970
template-body.blade.php
<body>
#yield('body')
<body>
template-html.blade.php
<html>
#include('template-body')
#yield('other')
</html>
foo.blade.php
#extends('template-html')
#section('body')
Hello World! (does not work)
#endsection
#section('other')
Does work
#endsection
what you are doing will give you an error. you can include pages on the template and other sub pages. it just depends on what you are doing and how you doing it. what you should have done is:
//app.layout
<!DOCTYPE html>
<html>
<head>
<title>#yield('title')</title>
<your-css-files>
#yield('styles')
<your-script files>
#yield('scripts')
</head>
<body>
#include('your page')
#yield('content')
</body>
</html>
then on your pages you do:
#extends(app.layout)
#section('content')
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
#include('your page')
#endsection
on the samepage you can call your styles and scripts as
#section('styles')
//css files
#stop
#section('scripts')
// javascript files
#stop
I am trying something really simple and can not get it to work.
I have 2 pages. admin.blade.php and left.blade.php
I am trying to use admin page as the master page. and include date from left.blade.php
The admin pages print only "test" as the result and includes nothing from left.admin.php.
I can`t see what is wrong. Thanks in advance
File structure is
-- resources
--views
*admin.blade.php
*left.blade.php
left.blade.php
#extends('admin')
#section('content')
baran
#stop
admin.blade.php
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title> #yield('title')</title>
</head>
<body>
<?php
// put your code here
?>
#yield('content')
test
<div id='footer'>
#yield('footer')
</div>
</body>
</html>
route command in web.php is
Route::get('/admin', function () {
return view('admin');
});
If you want to include date from left.blade.php you should use #include() directive in admin.blade.php:
#include('left')
If your main content is in left.blade.php and you're using admin.blade.php as layout only then change you route:
Route::get('/admin', function () {
return view('left');
});
You want to call the view for the inner page, not the master page, since the inner page extends the master page:
return view('left');
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