[英]Laravel 4 Blade weird behaviour
所以,我有這種代碼來打印我的索引頁:
class PageController extends MediaController {
protected $layout = 'layouts.main';
public function index_page() {
$data = array();
$data['title'] = 'Dynamic Title';
$data['css_files'] = array(
array('media'=>'all', 'file'=>'file1'),
array('media'=>'all', 'file'=>'file2')
);
$this->layout->content = View::make('index', $data);
}
}
和我的main.blade.php:
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
@yield('content')
@yield('css_files')
</body>
</html>
和我的index.blade.php:
@section('title', $title)
@section('css_files')
@foreach ($css_files as $css_file)
<p>File: {{ $css_file->file }}, Media: {{ $css_file->media }}</p>
@endforeach
@stop
@section('content')
<h1>Rendered Successfully!</h1>
@stop
標題呈現得很好,但是css文件顯示了以下內容:
文件:{{$ css_file-> file}},媒體:{{$ css_file-> media}}
文件:{{$ css_file-> file}},媒體:{{$ css_file-> media}}
代替這個:
文件:file1,媒體:全部
文件:file2,媒體:全部
誰能解釋為什么? 感謝您的幫助,我是Blade的新手。
- 編輯 -
我已經解決了這個問題,我碰巧在其中編輯Blade語法配置
供應商\\ laravel \\框架\\照亮\\視圖\\編譯器\\ BladeCompiler.php
從
protected $contentTags = array('{{', '}}');
/**
* Array of opening and closing tags for escaped echos.
*
* @var array
*/
protected $escapedTags = array('{{{', '}}}');
至
protected $contentTags = array('{=', '=}');
/**
* Array of opening and closing tags for escaped echos.
*
* @var array
*/
protected $escapedTags = array('{={', '}=}');
所以我應該用{=代替{{
希望這對以后的人有所幫助。
您在標題部分下方缺少@stop。 嘗試像這樣
@section('title')
{{ $title }}
@stop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.