【问题标题】:Blade not showing content in blade after @include - Laravel 4.2@include 之后刀片未在刀片中显示内容 - Laravel 4.2
【发布时间】:2016-06-26 04:58:54
【问题描述】:

我正在尝试基于 http referer 切换主布局。我目前正在提取正确的模板,但没有显示刀片中的内容——没有错误。 $layout 正在正确传递,因为模板会根据引用者进行更改。这个 404 刀片是唯一的问题。其他刀片可以很好地融入布局。

routes.php

App::missing(function($exception) {
    $referer = URL::previous();
    $layout = (strpos($referer,'ext')) ? 'layouts.ext.master' : 'layouts.master';
    return Response::view('error-404', compact('layout'), 404);
});

error-404.blade.php

@include($layout)

@section('page_content')
    content...
@stop

布局(/layouts/ext/master.blade.php 和 /layouts/master.blade.php 都包含 html 换行。)

@yield('page_content')

【问题讨论】:

    标签: php laravel laravel-4 blade laravel-routing


    【解决方案1】:

    使用@extends('layouts.ext.master') 而不是@include('layouts.ext.master')

    【讨论】:

    • Error in exception handler: View [@extends('layouts.master')] not found. 是不是因为如何包含句柄而没有被读取? layouts.master 确实存在
    • 你是对的,但描述性不够。如果您更新答案以解释为什么不应该使用 @include 而是使用 @extends 会有所帮助。 @include($layout) 变为 @extends($layout)
    【解决方案2】:

    请使用

    return View::make('error-404', compact('layout'));
    

    【讨论】:

      猜你喜欢
      • 2017-04-18
      • 2019-06-28
      • 2023-04-08
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多