在laravel 5中将HTML宏放在哪里? [英] Where to put HTML macros in laravel 5?
问题描述
在laravel 4中,我曾经拥有用于多个视图的HTML宏,例如:
In laravel 4 I used to have HTML macros which were used in multiple views, like:
HTML::macro('minipics', function($pic)
{
//
}
为此,我在/app
文件夹中有一个macros.php
文件.我找不到将这些宏放在laravel 5中的哪个位置.我应该为此使用宏"功能吗?
For that I had a macros.php
file in the /app
folder. I could not find out where to put the macros in laravel 5. Should I use the 'macroable' feature for that?
我最终使用了@include()
,并为其提供了所需的值.
I ended up using @include()
, giving it the needed values.
@include('shared.minipics', $mpics = $ppics)
@include('shared.minipics', $mpics = $randpics)
推荐答案
我已经将宏移到"resources/macros/..."目录中,因为我认为它们属于所有其他与视图相关的代码.要加载它们,我使用的服务提供商看起来像这样:
I've moved my macros into a "resources/macros/..." directory because I think they belong with all of the other view related code. To load them I'm using a service provider which looks something like this:
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class MacroServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
require base_path() . '/resources/macros/macro1.php';
require base_path() . '/resources/macros/macro2.php';
// etc...
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
这篇关于在laravel 5中将HTML宏放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!