laravel刀片包含错误-语法错误,意外 [英] laravel blade include error - syntax error, unexpected

查看:121
本文介绍了laravel刀片包含错误-语法错误,意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EasyPHP 14.1在本地使用Laravel 4. 我已经创建了一条路线:

I'm using Laravel 4 locally with EasyPHP 14.1. I have created a route :

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

布局(testlayout.blade.php):

a layout (testlayout.blade.php) :

<!doctype html>
<html>
<head>
    <title></title>
</head>
<body>
    <div class="container">
        @yield('container')
    </div>
</body>
</html>

和一个视图(test.blade.php):

and a view (test.blade.php) :

@extends("testlayout")
@section('container')
    <h1>Hello!</h1>
@stop

工作正常,我收到你好!"

It works fine and I get "Hello!"

但是,当通过添加如下包含内容来更改我的布局时:

But when a change my layout by adding an include like this :

<!doctype html>
<html>
<head>
    <title></title>
</head>
<body>
    <div class="container">
        @yield('container')
    </div>
        @include('testfooter')
</body>
</html>

使用我的页脚(testfooter.blade.php):

with my footer (testfooter.blade.php) :

@section("testfooter")
    <div class="footer">2013-2014</div>
@show

我有一个错误语法错误,意外的'/'".

I have an error "syntax error, unexpected '/'".

Laravel生成的代码(位于app \ storage \ views中)是错误的:

The code generated by Laravel (found in app\storage\views) is wrong :

<!doctype html>
<html>
<head>
    <title></title>
</head>
<body>
    <div class="container">
        <?php echo $__env->yieldContent('container')
    </div>
        <?php echo $__env->make('testfooter', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>; ?>
</body>
</html>

Laravel在yieldContent('container')之后忘记了;?>,并在... render()之后添加了两个;?>. 我已经尝试了很多事情,但是现在我真的没有任何头绪.

Laravel forgets ;?> after yieldContent('container') and adds two ;?> after ... render(). I've tried many things but I really don't have any clue now.

UPDATE1 我已经重新安装了一个新的Laravel和guest什么的,问题还是一样的.没有@include没关系,有了@include我会一次又一次遇到相同的错误.

UPDATE1 I have reinstalled a fresh Laravel and guest what, the problem is still the same. Without @include it's ok, with an @include I have the same error again and again.

UPDATE2和问题已解决(感谢@majimboo)! 这简直令人难以置信. 所有这些故事都与代码无关.这是文本编辑器的问题:Windows上的记事本.由于未知的原因,并且仅对于某些文件,它从编辑/EOL转换/Windows格式"切换为编辑/EOL转换/Mac格式".显然,Laravel根本不使用Mac格式!因此,如果您在Windows上使用Notepad ++,请确保具有:' EOL转换/Windows格式'

UPDATE2 and PROBLEM FIXED (thanks to @majimboo)! This is just unbelievable. All that story is not related to the code. This is a problem with the text editor : Notepad++ on Windows. For an unknown reason, and for somes files only, it switched from 'edit/EOL conversion/windows format' to 'edit/EOL conversion/Mac format'. And apparently, Laravel doesn't Mac format at all! So, if you use Notepad++ on Windows, be sure that you have : 'EOL conversion/windows format'

推荐答案

问题出在要包含的文件中.

the problem is in the file that is getting included.

首先检查问题是否确实存在,删除testfooter.blade.php中的所有内容,然后从浏览器中打开视图.您会发现不再有错误.

First to check if the problem is really that, remove everything inside testfooter.blade.php then open the view from the browser. You'll notice that there is no error anymore.

将您的testfooter.blade.php更改为:

<div class="footer">2013-2014</div>

删除@section("testfooter") ... @show.

示例:

<!-- app/views/header.blade.php -->

<h1>When does the Narwhal bacon?</h1>

<!-- app/views/footer.blade.php -->

<small>Information provided based on research as of 3rd May '13.</small>

您可以像这样添加它:

<!-- app/views/example.blade.php -->

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Narwhals</title>
</head>
<body>
    @include('header')
    <p>Why, the Narhwal surely bacons at midnight, my good sir!</p>
    @include('footer')
</body>
</html>

选中以了解有关刀片的更多信息.

Check this to learn more on blade.

问题似乎是其他原因,我想分享一下,如果它可以帮助您:

The problem seems to be something else, I would just like to share this, If it can help you:

我正在使用Notepad ++作为文本编辑器,并且出于某些奇怪的原因 决定使用"MAC格式"作为行尾(EOL)格式. 显然,Blade框架无法解决这一问题.使用 转换功能(在记事本++中:编辑-> EOL转换)进行转换 转换为Windows格式,它将可以正常工作...

I'm using Notepad++ as text-editor and for some strange reason it had decided to use "MAC format" as the End-Of-Line (EOL) format. Apparently the Blade framework can't cope with that. Use the conversion function (in notepad++ : Edit -> EOL Conversion) to convert to Windows Format and it will work just fine...

Arjen

这篇关于laravel刀片包含错误-语法错误,意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆