【问题标题】:Blade Template with comment on top not working顶部带有评论的刀片模板不起作用
【发布时间】:2013-06-05 21:05:16
【问题描述】:

文件:app/route.php

Route::get('/', function()
{
    return View::make('home');
});

文件:app/views/home.blade.php

{{-- Blade comment. --}}
@extends('layouts.base')

@section('head')
    <link rel="stylesheet" href="second.css" />
@stop

@section('body')
    <h1>Heading</h1>
    <p>Hello Home!</p>
@stop

文件:app/views/layouts/base.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    @section('head')
    <link rel="stylesheet" href="style.css" />
    @show
</head>
<body>
    @yield('body')
</body>
</html>

当我访问 laravel.localhost/ 它只输出 @extends('layouts.base')

但是,如果我删除了

{{-- 刀片注释。 --}}

那么它就完美运行了。

我可以知道是什么问题吗?

【问题讨论】:

    标签: laravel laravel-4 blade


    【解决方案1】:

    是的,这是开发人员的约定。 看BladeCompiler.php在线119

    protected function compileExtends($value)
        {
            // By convention, Blade views using template inheritance must begin with the
            // @extends expression, otherwise they will not be compiled with template
            // inheritance. So, if they do not start with that we will just return.
            if (strpos($value, '@extends') !== 0)
            {
                return $value;
            }
    

    【讨论】:

      【解决方案2】:

      扩展刀片视图中的第一行必须是 @extends 指令。

      【讨论】:

      • 这意味着我不能在文件顶部添加任何评论?
      • 在这种情况下,据我所知你不能,@extends 指令必须在最顶部,然后你可以写你的评论。
      猜你喜欢
      • 2014-11-15
      • 2016-03-11
      • 2013-06-04
      • 1970-01-01
      • 2013-02-03
      • 2018-05-28
      • 1970-01-01
      • 2017-07-31
      • 2019-06-26
      相关资源
      最近更新 更多