我有一个名为file-not-found.php的文件,具有不同的标题。我想要做的是根据路由名称或url段更改标题。
在CodeIgniter中,我可以这样做
function blah(){
include('layout.registered.header')
include('layout.file-not-found')
}
function unregistered(){
include('layout.unregistered.header')
include('layout.file-not-found')
}现在..。在不使用控制器的情况下,如何在Laravel模板中获得这一结果。我只使用路线和意见
我尝试了下面的方法,它调用中的扩展(如果是),并且在上调用扩展,因此它同时显示两个布局
file-not-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');
}));发布于 2014-06-18 06:01:57
你可以试试这个:
@extends(Route::currentRouteName() == 'file-not-found' ? 'layouts.unregistered' : 'layouts.registered')发布于 2014-06-18 06:02:18
你用的是哪种版本的Laravel?我相信,由于版本4.1,您需要使用Route:: current ()->getName()访问当前路由,而不是使用路由::currentRouteName()访问当前路由。
见https://github.com/laravel/framework/issues/2919。看来主文档还没有更新。
https://stackoverflow.com/questions/24277948
复制相似问题