du4373
2018-06-13 14:35 阅读 120
已采纳

如何在另一个指令中调用Laravel Blade指令?

I'm using the Wordpress framework Sage and it comes bundled with Blade templating. Sage has a custom directive called @asset which returns an asset URL. For example @assets('images/my-image.jpg').

I want to use that directive inside of an @include. Is it possible?

Example, I'd expect this to work but it returns an error saying that @asset is an undefined function, but it works fine outside of the @include:

@include('partials/components/hero', ['data' => [
    'heading' => 'Hero heading example from pattern library',
    'subtitle_1' => 'Hero subtitle example from pattern library',
    'subtitle_2' => 'Hero subtitle example from pattern library',
    'show_illustration' => true,
    'illustration_src' =>  @asset('images/illustrations/1.
]])
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douluyezhen4512 douluyezhen4512 2018-06-13 14:47

    You cannot.
    You can however just send the path string to your partial and use the @asset directive in your partial.

    点赞 评论 复制链接分享
  • donglei_0507 donglei_0507 2018-06-13 14:50

    You should be able to use the asset() helper function instead or pass the string directly to the path of your asset.

    Note: Based on the code you have shown (@asset('images/illustrations/1.) that is incorrect syntax. It is missing the closing quote and bracket.

    点赞 评论 复制链接分享

相关推荐