【发布时间】:2013-12-23 07:23:52
【问题描述】:
我对 Laravel 很陌生,我正在尝试弄清楚如何使用模板。
我很确定我在这里的东西应该可以工作,但是当我运行它时我一直收到错误消息。我认为这与必须在同一行上使用 @yield 命令有关。这仅仅是刀片引擎的限制吗?
routes.php
Route::get('/', function()
{
return View::make('hello');
});
// Test Route:
Route::get('jtest', function(){
$page = array(
"lang" => "en",
"title" => "jtest",
"css" => "css/layout.css",
"rand" => rand()
);
return View::make('jtest')->with('page', $page);
});
jtest.blade.php
@extends('layout')
@section('html-lang')
@if ( isset($page['lang']) )
{{ $page['lang'] }}
@endif
@endsection
@section('title')
@if ( isset($page['title']) )
{{ $page['title'] }}
@endif
@endsection
@section('meta-description')
@if ( isset($page['meta-description']) )
{{ $page['meta-description'] }}
@endif
@endsection
@section('css')
@if ( isset( $page['css'] ) )
{{ $page['css'] }}
@endif
@endsection
@section('rand')
@if ( isset( $page['rand'] ) )
{{ $page['rand'] }}
@endif
@endsection
layout.blade.php
<!doctype html>
<html lang="@yield('html-lang')">
<head>
<meta charset="utf-8">
<title>@yield('title')</title>
<meta name="description" content="@yield('meta-description')">
<meta name="author" content="Jimmy Hogoboom">
<link rel="stylesheet" href="@yield('css')?r=@yield('rand')">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script src=""></script>
</body>
</html>
错误是
syntax error, unexpected '='
错误所在的行如下所示:
<link rel="stylesheet" href="<?php echo $__env->yieldContent('css')?r=@yield('rand'); ?>">
所以问题就在这里:
<link rel="stylesheet" href="@yield('css')?r=@yield('rand')">
如果我删除第二个@yield:
<link rel="stylesheet" href="@yield('css')?r=">
页面加载正常。
所以这只是刀片的限制,还是有其他方法我应该将这些值放在页面中?
【问题讨论】: