Skip to content

Conversation

@jesseleite
Copy link
Contributor

@jesseleite jesseleite commented Jan 11, 2022

Resurrecting a version of the work done by @riasvdv in #2724 and #2717 (🎉) to bring antlers support to blade via convenient wrappers.

We don't want to pollute the global namespace, but as a Statamic:: accessible function, we're thinking it would be nice to bring this kind of antlers support to blade.

The nice thing about Rias' approach here is that it'll allow the user to work with / loop over the output however they want in blade (ie. @foreach, @forelse, pass data into an @include, etc) 👍

TODO:

  • Add FluentTag helper class, inspired by our fluent Modify helper class.
  • Add Statamic::tag() wrapper.
  • Add Statamic::modify() wrapper.
  • Add test coverage.

Example Statamic::tag() blade usage:

{{-- // Loop over results however you want in blade --}}
@foreach(Statamic::tag('collection:pages') as $page)
	{{ $page['title'] }}<br>
@endforeach

{{-- // Fluently add tag params --}}
@foreach(Statamic::tag('collection:pages')->sort('date:desc')->limit(3) as $page)
	{{ $page['title'] }}<br>
@endforeach

{{-- // Pass in contextual data --}}
@foreach(Statamic::tag('collection:pages')->context($context) as $page)
	{{ $page['title'] }}<br>
@endforeach

{{-- // Disable augmentation --}}
@foreach(Statamic::tag('collection:pages')->withoutAugmentation() as $page)
	{{ $page['title'] }}<br>
@endforeach

Example Statamic::modify() blade usage:

{{ Statamic::modify($title)->upper()->ensureRight('!!!') }}

@jesseleite jesseleite marked this pull request as draft January 11, 2022 22:26
@jesseleite jesseleite changed the base branch from 3.2 to master January 11, 2022 22:29
@riasvdv
Copy link
Contributor

riasvdv commented Jan 12, 2022

I've had to add the $context parameter to mine as well for some cases, so it would be good to have that as well, see https://github.com/riasvdv/rias.be/blob/main/app/helpers.php#L26-L46

@riasvdv
Copy link
Contributor

riasvdv commented Jan 12, 2022

Also, I'd prefer Statamic::tag(), as it's nice and short, maybe we could have Statamic::modify() as well then to keep things consistent?

@jesseleite jesseleite marked this pull request as ready for review January 13, 2022 19:25
@jesseleite jesseleite requested a review from jasonvarga January 13, 2022 19:26
@jesseleite
Copy link
Contributor Author

@riasvdv we opted for a more fluent approach, taking inspiration from our Modify helper class, so that both Statamic::tag() and Statamic::modify() can be used fluently. See updated examples above 🤘

@jesseleite jesseleite merged commit 23b4929 into master Jan 13, 2022
@jesseleite jesseleite deleted the feature/antlers-tag-wrapper-for-blade branch January 13, 2022 19:48
@riasvdv
Copy link
Contributor

riasvdv commented Jan 13, 2022

Amazing! Looking forward to being able to update my blogpost on how easy it is when this is released 😄

@jesseleite
Copy link
Contributor Author

Cool, do share when done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants