Laravel使用" @布局"在Ajax的请求 [英] Laravel usage "@layout" in Ajax Requests

查看:162
本文介绍了Laravel使用" @布局"在Ajax的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好计算器!

在我laravel的观点我使用的是默认的布局,通过调用

In my laravel views I am using a default layout by calling

@layout('layouts.default')

到同一控制器我发送Ajax请求但我不能把'如果',以@layout如果一个Ajax调用。因为如果AJAX请求作出控制器也产生页眉,页脚和内容(页眉和页脚是默认的布局)。因此,要避免这一点,我做了一个副本,而不@layout了我的看法。

to the same controller I am sending Ajax Requests yet I can't put 'if' to @layout if its a ajax call. Because if ajax request has made to controller it also produce header, footer and content(header and footer are in default layout). So to avoid this I made one copy without @layout of my view.

不过它太无聊编辑两个文件进行更改。我不能添加一个code我的看法是这样的:

However its so boring to edit two files for making changes. Can't I add a code to my view something like that?:

@if(!$ajaxrequest)
 @layout('layouts.master')
@endif

我想这是因为我的codeS的控制器是太乱了

I want this because my codes in controllers are too messy

推荐答案

您不能有 @layout 通话后if语句那样(见的通知在刀锋模板红在文档。你必须设置公共$布局和呼叫 $这个 - >布图设计>巢而不是查看::让(请参见基础链接到上面的页面)。

You can't have the @layout call after the if statement like that (see the notice in red under "Blade Templating" in the docs. You'll have to set the public $layout and call $this->layout->nest instead of View::make (see "The Basics" on the page linked to above).

这篇关于Laravel使用" @布局"在Ajax的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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