i'm learning Laravel frame work, and have a question:
in this code:
<!DOCTYPE HTML>
<html>
<body>
<nav>
#section('nav')
<a>Home page</a>
#show
</nav>
<div id="content">
#yield('content')
</div>
</body>
</html>
what to do: #show ?!
Having a layout (layout.blade.php) view of
<!DOCTYPE HTML>
<html>
<body>
<nav>
#section('nav')
<a>Home page</a>
#show
</nav>
<div id="content">
#yield('content')
</div>
</body>
</html>
And a view (users.blade.php) of
#extends('layout')
#section('nav')
> <a>Users</a>
#stop
You should see rendered:
Home page > Users
But you could also use stop on layout:
#section('nav')
<a>Home page</a>
#stop
And #parent on your view:
#section('nav')
#parent
> <a>Users</a>
#stop
Take a look at video's 6 and 7 regarding "blade basics" and "master pages"
https://laracasts.com/series/laravel-from-scratch
Related
I'm newbie in laravel. When I try to make master layout example, I get the content of my view printed out twice.
master.blade.php:
<html>
<head>
<title>#yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
page.blade.php:
#extends('layouts.master')
#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
and my Route web.php:
Route::get('blade', function () {
return view('page');
});
I trying use #stop intead of #endsection but it doesn't work.
I have a master_page.blade with global content for my html:
<!DOCTYPE html>
<html lang="es">
<head>
#include('layout.head')
</head>
<body>
#include('layout.header')
#yield('master_content')
#section('footer')
#include('layout.footer')
#show
#include('layout.scripts')
#yield('custom_scripts')
</body>
</html>
After, I have a layout in Bootstrap with 2-6 columns, this blade inherit of the master_blade, his name is 2_10_columns.blade:
#extends('layout.master_page')
#section('master_content')
<div class="container">
<div class="main-content">
<div class="col-sm-2">
#section('content1')
#show
</div>
<div class="col-sm-10">
#section('content2')
#show
</div>
</div>
</div>
#stop
Ok, this looks good but, finally I need fill the 2_10_columns.blade with some content, for example I tried this with mi contact.blade.php:
#extends('layout.2_10_columns')
#section('content1')
<p>Column 2 left content of my section...</p>
#stop
#section('content2')
<p>Column 10 right content of my section ...</p>
...some forms here
#stop
Definitely this does not work...
How could I do this with Laravel? Look at this infographic:
its working like this(simplified for example):
master layout:
<html>
<body>
<div class="container">
#yield('master_content')
</div>
</body>
</html>
2 cols layout:
#extends('layouts.master')
#section('master_content')
<div class="co-l2">
<p>index</p>
#yield('sidebar')
</div>
<div class="col-10">
#yield('content')
</div>
#endsection
contact view:
#extends('layouts.2cols')
#section('sidebar')
<p>delete</p>
#endsection
#section('content')
<h1> person name </h1>
<p>about the person</p>
#endsection
my html code is
<html>
<head>
</head>
<body>
<div id="content">
<div id="menu"></div>
<div id="container"></div>
<div id="sidebar"></div>
<div id="footer"></div>
<div>
</body>
</html>
master.blade.php is
<html>
<head>
#yield('title')
#yield('css')
#yield('js')
</head>
<body>
<div id="content">
<div id="container"></div>
<div>
</body>
</html>
menu.blade.php is
<div id="menu"></div>
sidebar.blade.php is
<div id="sidebar"></div>
footer.blade.php is
<div id="footer"></div>
my view file is home.blade.php
#extends('layouts.master')
#section('title')
<title>:: Login ::</title>
#stop
#section('js')
#stop
#extends('layouts.menu')
#extends('layouts.sidebar')
#extends('layouts.footer')
router.php
Route::get('home', array('uses' => 'HomeController#home'));
HomeController.php is
public function home()
{
return View::make('home');
}
id i run
localhost/project/public/index.php/home
it shows only master blade file content , y sidebar , footer and menu not showing , what is the mistake.
Create a your layout #including your menu:
<html>
<head>
<title>#yield('title')</title>
#yield('css')
#yield('js')
</head>
<body>
<div id="content">
<div id="container">
#include('menu')
#yield('content')
</div>
</body>
</html>
Your menu:
<div id="menu">
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</div>
And your view:
#extends('layouts.master')
#section('title')
:: Login ::
#stop
#section('content')
This is your content!
#stop
This is my scenario:
I have made a main.blade.php and it contains the following code:
<!DOCTYPE html>
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
<div id='header'>
#yield('header')
</div>
<div id='main-wrapper'>
#yield('content')
</div>
<div id='footer'>
#yield('footer')
</div>
</body>
</html>
And then this is the controller:
class Userindex extends BaseController
{
protected $layout = "main";
function register ()
{
$this->layout = View::make("user.register")
->with("title","Registration");
}
}
Here is the register.blade.php in user folder:
#extends('main')
#section('content')
<p>This the content of the page register.</p>
#stop
My PROBLEM: I have two other pages as header.blade.php and footer.blade.php that I don't know how should I include them into the register.blade.php
Do a little adjustment to you layout file, replace #yield with #include and that's it!
<!DOCTYPE html>
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
<div id='header'>
#include('partials.header')
</div>
<div id='main-wrapper'>
#yield('content')
</div>
<div id='footer'>
#include('partials.footer')
</div>
</body>
</html>
I'm trying to include a template (widget.blade.php) inside a template (master.blade.php) as below. both templates use sections named 'content' but the widget output uses the content from the master instead of the widget content.
master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>
#section('title')
#show
</title>
</head>
<body>
<div>
#section('content')
#show
</div>
<div>
#section('sidebar')
#show
</div>
</body>
</html>
widget.blade.php
<div class="widget">
#section('content')
#show
</div>
index.blade.php
#extends('master')
#section('content')
Main Content
#stop
#section('sidebar')
#include('mywidget')
#stop
mywidget.blade.php
#extends('widget')
#section('content')
My Widget Content
#stop
The final result
Main Content
Main Content
Any ideas how to fix this collision?
This could be fixed by using #overwrite instead of #stop
#extends('widget')
#section('content')
My Widget Content
#overwrite
source:
http://laravel.com/docs/templates#other-blade-control-structures