Roots Discourse

Blade Directives for Sage


#1

While this package was released a couple weeks ago, I have just completed the documentation for it and thought now would be the appropriate time to share.

:heart:


#2

Hi Log1x,

Thanks for this! It looks great and I appreciate the documentation.

I have a few questions if you don’t mind assisting.

Previously I might have had some code like the following:

@if (get_sub_field('type') == 'type-h1')
	<h1>
		@sub('heading')
	</h1>
@elseif (get_sub_field('type') == 'type-h2')
	<h2>
		@sub('heading')
	</h2>
@endif

With your directives I found I can use something like:

@issub('type', 'type-h1')
<h1>@sub('heading')</h1>
@endsub

@issub('type', 'type-h2')
<h2>@sub('heading')</h2>
@endsub

But if I didn’t want to just check if something was equal to something else, perhaps not equal to, I would have to use my original method. However I wanted to keep the syntax the same and use your directives but then I found using @sub within the @if produced php errors.

Do you have a way in which I can use the @sub within the @if so I can keep the code written all the same way and not keep jumping between @sub() and get_sub_field() ? If not, all good I just wanted to also confirm I’m just not writing something incorrectly.

Cheers,


#3

Unfortunately, Blade will not render directives inside of directives.

You could use something that can chain off the if statement of @issub though such as @else.

e.g.

@issub('type', 'type-h1')
	<h1>
		@sub('heading')
	</h1>
@else
	<h2>
		@sub('heading')
	</h2>
@endsub

Feel free to open an issue on the repo if you have any sane suggestions for directives that others might find useful as well.