diff --git a/README.md b/README.md index e5f1f69..c786791 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,25 @@ if you want to include a component from a dynamic variable you can use the `live ``` +### @script and @assets +Antlers versions of [@script](https://livewire.laravel.com/docs/javascript#executing-scripts) and [@assets](https://livewire.laravel.com/docs/javascript#loading-assets) are provided: + +```html + + {{ livewire:script }} + + {{ /livewire:script }} + +``` + +```html + + {{ livewire:assets }} + + {{ /livewire:assets }} + +``` + ### Blade or Antlers? Both! If creating a Livewire component, you need to render a template file diff --git a/src/Tags/Livewire.php b/src/Tags/Livewire.php index d1a3c4f..5aee3d7 100644 --- a/src/Tags/Livewire.php +++ b/src/Tags/Livewire.php @@ -96,4 +96,37 @@ public function scriptConfig(): string { return \Livewire\Mechanisms\FrontendAssets\FrontendAssets::scriptConfig(); } + + /** + * Antlers implementation of @assets - https://livewire.laravel.com/docs/javascript#loading-assets + * + * {{ livewire:assets }}....{{ /livewire:assets }} + */ + public function assets(): void + { + $html = (string) $this->parse(); + + $key = md5($html); + + if (in_array($key, \Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys)) { + // Skip it... + } else { + \Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys[] = $key; + \Livewire\store($this->context['__livewire'])->push('assets', $html, $key); + } + } + + /** + * Antlers implementation of @script - https://livewire.laravel.com/docs/javascript#executing-scripts + * + * {{ livewire:script }}...{{ /livewire:script }} + */ + public function script(): void + { + $html = trim((string) $this->parse()); + + $key = md5($html); + + \Livewire\store($this->context['__livewire'])->push('scripts', $html, $key); + } }