Skip to content

Commit

Permalink
Merge pull request #69 from ryanmitchell/feature/allow-for-dynamic-co…
Browse files Browse the repository at this point in the history
…mponent-names

Allow for dynamic component names
  • Loading branch information
jonassiewertsen committed Sep 9, 2024
2 parents be2b8b1 + 3c649b6 commit ad7726f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ To include your Livewire component:
</body>
```
if you want to include a component from a dynamic variable you can use the `livewire:component` tag:
```html
<body>
<!-- If using Antlers -->
{{ livewire:component :name="variable" }}

<!-- If using Blade -->
<livewire:component name="$variable" />
</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:
Expand Down
10 changes: 10 additions & 0 deletions src/Tags/Livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public function wildcard($expression): string
{
return \Livewire\Livewire::mount($expression, $this->params->except('key')->toArray(), $this->params->only('key')->first());
}

/**
* This will load your Livewire component in the Antlers view
*
* {{ livewire:component name="my-component" }}
*/
public function component(): string
{
return $this->wildcard($this->params->pull('name'));
}

/**
* Sharing State Between Livewire And Alpine via entangle.
Expand Down

0 comments on commit ad7726f

Please sign in to comment.