douyin2962 2019-06-20 09:36
浏览 1079

如何扩展laravel blade指令@extends?

I am developing a large system in Laravel. The idea is to create modules and add them to their own repository. I want to make it as generic as possible.

The problem is with the(view)namespaces of laravel. I want to give the user of the package the ability to change the path of the views and if he wants the namespace of the views (Give it the ability to use functionality but using custom views).

This results in a problem with the blade directives @extends, @include and @component.

Having no way to generic use the view namespaces.

Having to put the namespace first in every blade like this:

@extends('user::layouts.web')

Will give the problem that the namespace can never be changed from configuration files.

Other things i tried was using a constant and config for the namespace.

@extends(App\Providers\UserServiceProvider::MODULE_SLUG.'::layouts.web')

@extends(config('user.module.viewNamespace') . '::layouts.web')

Those 2 work but I do not want to type in the configuration path or Provider namespace every time.

I Think that my best solution is writing custom directives @extends, @includes and @components for every module (this will be done dynamically).

You would get the following directives: @userExtends @userInclude @userComponent

The last problem that I am running into is that I cannot find a way to extend the existing @extends directive.

Any suggestions?

  • 写回答

1条回答 默认 最新

  • dongqiao2077 2019-06-20 10:14
    关注

    Maybe this is something that can get you on the correct route: https://laravel.com/docs/5.8/packages#views

    评论

报告相同问题?

悬赏问题

  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法