2015-08-03 20 views
0

如何爲所有頁面製作一種佈局?例如我有:Laravel在所有頁面中的一種佈局

header.blade.php文件與我的標題。

<!doctype html> 
<head> 
<meta charset="utf-8"> 
<!-- Latest compiled and minified CSS --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 

    <!-- Optional theme --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> 

    <!-- Latest compiled and minified JavaScript --> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"> 
</script> 
</head> 
<body> 

而且在login.blade.php:

@extends('layouts.header') 
<form method="POST" action="/auth/login"> 
    {!! csrf_field() !!} 

    <div> 
     Email 
     <input type="email" name="email" value="{{ old('email') }}"> 
    </div> 

    <div> 
     Password 
     <input type="password" name="password" id="password"> 
    </div> 

    <div> 
     <input type="checkbox" name="remember"> Remember Me 
    </div> 

    <div> 
     <button type="submit">Login</button> 
    </div> 
</form> 
</body> 

但是當我打開登錄頁登錄後我的頭打印?爲什麼? 喜歡這個問題: Error

也許存在更簡單的方法來使用所有頁面的頁眉/頁腳?例如:

@extends('layouts.header') 
~~somethingfile.php~~ 
@extends('layouts.footer') 

在此先感謝

回答

2

在頭文件內容的末尾插入 @yield( '內容')

然後,當你可以這樣寫

@extends ('layouts.header') @section('content') 〜somethings〜 @stop @extends('layouts.footer')

我認爲這可能對你有幫助。

3

您通常會創建這樣一個佈局文件:

<html> 
    <head> 
     <title>App</title> 
    </head> 
    <body> 
     @yield('header') 

     <div class="container"> 
      @yield('content') 
     </div> 

     @yield('footer') 

    </body> 
</html> 

和所有其他文件擴展了此文件,@extends('layout.layout'),具有@section自己的內容。

@section('content') 
     // content 
@endsection 

@section('header') 
     // content 
    @endsection 

根據目的,等等。

看一看documentation

+0

非常感謝! :) –

+0

不客氣! @ Evaldas888 – baao