Skip to content

Commit

Permalink
Merge branch 'master' into feature/allow-for-dynamic-component-names
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Sep 9, 2024
2 parents bec149d + be2b8b1 commit 3c649b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ if you want to include a component from a dynamic variable you can use the `live
</body>
```
### @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
<body>
{{ livewire:script }}
<script>console.log('hello')</script>
{{ /livewire:script }}
</body>
```
```html
<body>
{{ livewire:assets }}
<script src="some-javascript-library.js"></script>
{{ /livewire:assets }}
</body>
```
### Blade or Antlers? Both!
If creating a Livewire component, you need to render a template file
Expand Down
33 changes: 33 additions & 0 deletions src/Tags/Livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3c649b6

Please sign in to comment.