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:

13 Likes

#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,

0 Likes

#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.

0 Likes

#6

Massive update with the release of 1.0.4 a few weeks ago as well as new documentation:

https://log1x.github.io/sage-directives-docs/

Please open an issue on GitHub if you spot any bugs, otherwise– any support and/or questions can be done on this thread. :slight_smile:

0 Likes

#7

Hi, is there any way to check if a user role is applied to a user and display different content based on role?

0 Likes

#8

Not at the moment but it’s a good suggestion. I’ll see if I can finalize v1.0.7 today (mainly just need to clean up the docs) and I’ll add @role.

1 Like

#9

v1.0.7 is released.

Enhancements

  • Add Sage 10 support :balloon:
  • @sub and @hassub can now accept a third parameter for deeper nested arrays (e.g. @sub('images', 'sizes', 'thumbnail')).
  • New @permalink, @category, @categories, @term, @role, and @endrole directives.

Bugfixes

  • Change get() to a protected function.
  • Fix a few typos in the docs.
3 Likes