Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 3c649b6

Browse files
authored
Merge branch 'master' into feature/allow-for-dynamic-component-names
2 parents bec149d + be2b8b1 commit 3c649b6

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ if you want to include a component from a dynamic variable you can use the `live
120120
</body>
121121
```
122122
123+
### @script and @assets
124+
Antlers versions of [@script](https://livewire.laravel.com/docs/javascript#executing-scripts) and [@assets](https://livewire.laravel.com/docs/javascript#loading-assets) are provided:
125+
126+
```html
127+
<body>
128+
{{ livewire:script }}
129+
<script>console.log('hello')</script>
130+
{{ /livewire:script }}
131+
</body>
132+
```
133+
134+
```html
135+
<body>
136+
{{ livewire:assets }}
137+
<script src="some-javascript-library.js"></script>
138+
{{ /livewire:assets }}
139+
</body>
140+
```
141+
123142
### Blade or Antlers? Both!
124143
If creating a Livewire component, you need to render a template file
125144

src/Tags/Livewire.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,37 @@ public function scriptConfig(): string
9696
{
9797
return \Livewire\Mechanisms\FrontendAssets\FrontendAssets::scriptConfig();
9898
}
99+
100+
/**
101+
* Antlers implementation of @assets - https://livewire.laravel.com/docs/javascript#loading-assets
102+
*
103+
* {{ livewire:assets }}....{{ /livewire:assets }}
104+
*/
105+
public function assets(): void
106+
{
107+
$html = (string) $this->parse();
108+
109+
$key = md5($html);
110+
111+
if (in_array($key, \Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys)) {
112+
// Skip it...
113+
} else {
114+
\Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys[] = $key;
115+
\Livewire\store($this->context['__livewire'])->push('assets', $html, $key);
116+
}
117+
}
118+
119+
/**
120+
* Antlers implementation of @script - https://livewire.laravel.com/docs/javascript#executing-scripts
121+
*
122+
* {{ livewire:script }}...{{ /livewire:script }}
123+
*/
124+
public function script(): void
125+
{
126+
$html = trim((string) $this->parse());
127+
128+
$key = md5($html);
129+
130+
\Livewire\store($this->context['__livewire'])->push('scripts', $html, $key);
131+
}
99132
}

0 commit comments

Comments
 (0)