James Tudsbury
James Tudsbury

Reputation: 93

How can you call a Laravel Blade directive inside of another directive?

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.
]])

Upvotes: 3

Views: 1713

Answers (2)

Script47
Script47

Reputation: 14550

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.

Upvotes: 2

Jerodev
Jerodev

Reputation: 33196

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

Upvotes: 3

Related Questions