包括不同的标题到同一页面

时间:2014-06-18 05:51:53

标签: php laravel laravel-4 blade

我有一个名为file-not-found.php的文件和不同的标题..我想要做的是根据路线名称或网址段更改标题

CodeIgniter 我可以这样做

function blah(){
    include('layout.registered.header')
    include('layout.file-not-found')
}

function unregistered(){
    include('layout.unregistered.header')
    include('layout.file-not-found')
}

现在..如何在不使用控制器的情况下在Laravel Blade Templating中获得此信息。 我只使用路线和观点

我尝试了下面的方法并调用 IF 中的扩展,并调用 ELSE 中的扩展名,以便同时显示2个布局

文件未found.blade.php

@if (Route::currentRouteName() == 'file-not-found')
    @extends('layouts.unregistered')

@else
    @extends('layouts.registered')

@endif

路线

Route::get('/file-not-found', array('as' => 'file-not-found', function()
{
    return View::make('pages.new.file-not-found');
}));


Route::get('registered/file-not-found', array('as' => 'registered', function()
{
    return View::make('pages.new.file-not-found');
}));

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

@extends(Route::currentRouteName() == 'file-not-found' ? 'layouts.unregistered' : 'layouts.registered')

答案 1 :(得分:0)

您使用的是哪个版本的Laravel?我相信自4.1版以来你需要使用Route :: current() - > getName()而不是Route :: currentRouteName()来访问当前路由。

https://github.com/laravel/framework/issues/2919。主要文档似乎尚未更新