Skip to content

[7.x] Once Blocks#33812

Merged
taylorotwell merged 4 commits into
7.xfrom
once-blocks
Aug 10, 2020
Merged

[7.x] Once Blocks#33812
taylorotwell merged 4 commits into
7.xfrom
once-blocks

Conversation

@taylorotwell

Copy link
Copy Markdown
Member

Proof of concept for @JeffreyWay ...

Component content here...

@once
    <script>
        This will only be included in the template once even if component is rendered multiple times.
    </script>
@endonce

@GrahamCampbell GrahamCampbell changed the title Once Blocks [7.x] Once Blocks Aug 10, 2020
@JeffreyWay

Copy link
Copy Markdown
Contributor

Wew!

image

@taylorotwell taylorotwell merged commit de6b106 into 7.x Aug 10, 2020
@taylorotwell taylorotwell deleted the once-blocks branch August 10, 2020 20:01
@calebporzio

Copy link
Copy Markdown
Contributor

Woop Wooop!

@eduardoarandah

Copy link
Copy Markdown

‪it would benefit a lot having a key 🔑 and dependencies so it’s rendered in the right order.
Also version, for cache busting

‪This problem has already been solved in Wordpress. Check this out

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

@julienbourdeau

julienbourdeau commented Aug 10, 2020

Copy link
Copy Markdown

@eduardoarandah I think the <script> was just a random example. I don't think it's meant for including your assets at all.

@Braunson

Copy link
Copy Markdown

I ran into a use-case today where this would have came in handy!

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This will be available in Laravel 7.25.0, tomorrow. ;)

@themsaid

Copy link
Copy Markdown
Member

Here's an actual use case:

image

This component renders to a list of receipts. The for the receipt has to be rendered once in the entire page while the component itself can be used multiple times.

@adxmcollins

Copy link
Copy Markdown

Ha, talk about timing! This will come in really handy for something I’m currently building!

@marchampson

Copy link
Copy Markdown

Great job - I can see this being used a lot.

@juninhodeluca

Copy link
Copy Markdown

I think every dev which uses components already has your own implementation of push once at this time. Almost all based on this sw

https://stackoverflow.com/questions/38135455/how-to-have-one-time-push-in-laravel-blade

@brenjt

brenjt commented Aug 11, 2020

Copy link
Copy Markdown

I love this. I can also see the ability to use this like the @push() but a @pushonce('scripts') directive.

@epalmans

Copy link
Copy Markdown
Contributor

@brenjt agree #30104 :-)

dsturm added a commit to dsturm/acorn that referenced this pull request Aug 12, 2020
Using the new [@once Blocks](laravel/framework#33812) currently fails, since the mandatory library for UUIDs is missing.
QWp6t pushed a commit to roots/acorn that referenced this pull request Aug 12, 2020
Using the new [@once Blocks](laravel/framework#33812) currently fails, since the mandatory library for UUIDs is missing.
@gauravmak

Copy link
Copy Markdown
Contributor

Is the documentation updated already?

@driesvints

Copy link
Copy Markdown
Member

@gauravmak no but feel free to send in a PR. Otherwise I'll try to do so when I'm back from vacation.

@JunaidQadirB

Copy link
Copy Markdown

I use @stack @push a lot in my blade components. It will be really useful for my use-case. Awesome!

@zhabinskiy

Copy link
Copy Markdown

@driesvints @gauravmak I just sent a PR on updating docs laravel/docs#6255

hackhero920 added a commit to hackhero920/acorn that referenced this pull request Aug 15, 2023
Using the new [@once Blocks](laravel/framework#33812) currently fails, since the mandatory library for UUIDs is missing.
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.