Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Once Blocks #33812

Merged
merged 4 commits into from
Aug 10, 2020
Merged

[7.x] Once Blocks #33812

merged 4 commits into from
Aug 10, 2020

Conversation

taylorotwell
Copy link
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
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
Contributor

Woop Wooop!

@eduardoarandah
Copy link

‪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
Copy link

julienbourdeau commented Aug 10, 2020

@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

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

@GrahamCampbell
Copy link
Member

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

@themsaid
Copy link
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

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

@marchampson
Copy link

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

@juninhodeluca
Copy link

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
Copy link

brenjt commented Aug 11, 2020

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

@epalmans
Copy link
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
Contributor

Is the documentation updated already?

@driesvints
Copy link
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

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

@zhabinskiy
Copy link

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