简体   繁体   English

Laravel-用另一个覆盖刀片模板

[英]Laravel - Overwrite Blade Template with another

I'm using Laravel 4.1.30 我正在使用Laravel 4.1.30

I was wondering if it's possible to to overwrite a template with a different template: 我想知道是否可以用其他模板覆盖一个模板:

Like this I would have: 这样,我将拥有:

Show.blade.php

The i would make in the same directory it's located: 我将在它所在的同一目录中进行创建:

 _Show.blade.php

That second file would have the same content as the original, but able to be modified, that way i don't have to change the original. 第二个文件将具有与原始文件相同的内容,但是能够被修改,这样我就不必更改原始文件。

Is this possible in laravel, or would that be impossible? 在laravel中这可能吗,还是不可能?

I guess you can write a function. 我猜你可以写一个函数。 to give you an idea, this code is not entirely php: 给你一个想法,这段代码并不完全是php:

$template = 'show.view.php';

if(file_exists('_' . $template)){
    return '_' . $template;
}else{
    $template;
}

For Laravel 4.2.x 对于Laravel 4.2.x

Well i couldn't find a way to do the hierarchy for files but there is a method for folders. 好吧,我找不到一种方法来处理文件的层次结构,但是有一种文件夹的方法。 Found the answer a while back. 前一段时间找到了答案。

So we would first go to: 所以我们首先去:

app/start/global.php <- global classloader

and add: 并添加:

View::addLocation(public_path('app/views'));

Then go to: 然后转到:

app/config/view.php

and change: 并更改:

/*
|--------------------------------------------------------------------------
| View Storage Paths
|--------------------------------------------------------------------------
|
| Most templating systems load templates from disk. Here you may specify
| an array of paths that should be checked for your views. Of course
| the usual Laravel view path has already been registered for you.
|
*/

'paths' => array(__DIR__.'/../views'),

to: 至:

/*
|--------------------------------------------------------------------------
| View Storage Paths
|--------------------------------------------------------------------------
|
| Most templating systems load templates from disk. Here you may specify
| an array of paths that should be checked for your views. Of course
| the usual Laravel view path has already been registered for you.
|
*/

'paths' => array(__DIR__.'/../views-custom'),

You can change 'views-custom' to whatever you like but all changes made within that folder will be preferred over the 'views' folder. 您可以将“ views-custom”更改为任意选项,但在该文件夹中进行的所有更改都将优先于“ views”文件夹。 So its more of a folder hierarchy option. 因此,它更多是一个文件夹层次结构选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM