Download the PHP package rainlab/livewire-plugin without Composer
On this page you can find all versions of the php package rainlab/livewire-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rainlab/livewire-plugin
More information about rainlab/livewire-plugin
Files in rainlab/livewire-plugin
Package livewire-plugin
Short Description Load and render Livewire components using Twig inside October CMS themes.
License
Informations about the package livewire-plugin
Livewire Plugin
Integrate Laravel Livewire components inside October CMS themes, app and plugins, with templates provided by Twig, Blade or PHP.
Requirements
- October CMS v3.3.9 or above
Installation
To install with Composer, run this from your project root.
Rendering Livewire Components
Use the livewire
CMS component to activate Livewire in your CMS theme page or layout. For example, your page may look like this.
Next, render a Livewire component using the {% livewire %}
Twig tag.
You may pass variables to the component using an equal sign (=
).
Note: For proper operation, your CMS layout should include the
{% styles %}
and{% scripts %}
placeholder tags, as described in the placeholder documentation.
File Locations
By default, classes are stored in the app/Livewire directory. However, you can register custom classes within plugins (see below).
Views are stored in the in app/views/livewire directory by default. The following template syntaxes are supported in the views directory, determined by their file extension.
Extension | Template Engine |
---|---|
.htm | October Twig |
.blade.php | Laravel Blade |
.php | PHP Template |
Plugin Registration
To register Livewire components in your plugins using the registerLivewireComponents
override method. The method should return a class name as the key and the component alias as the value.
In the above example, the October\Demo\Livewire\Todo
class refers to the following file locations:
- Class file: plugins/october/demo/livewire/Todo.php
- View file: plugins/october/demo/views/livewire/todo.htm.
The class should return its view path by overriding the render
method, and returns a View instance relative to the plugin.
The component can be rendered anywhere using the demoTodo
alias.
Usage in CMS Components
You may implement Livewire in your CMS components using the RainLab\Livewire\Behaviors\LivewireComponent
behavior. This implementation will ensure that the necessary dependencies are registered when the component is used.
Then render the component using the {% livewire %}
tag.
Alternatively, you can render the component in PHP using the renderLivewire
method.
Usage in Backend Controllers
You may implement Livewire in your backend controllers using the RainLab\Livewire\Behaviors\LivewireController
behavior. This implementation will ensure that the necessary dependencies are registered with the controller.
Then render the component using the makeLivewire
method.
Usage Example
Here we will create a component in the app directory and render it on a CMS page freestanding. First, create a file called app/views/livewire/counter.htm with the following content.
Create a file called app/Livewire/Counter.php with the following contents.
This component now be rendered as counter in your CMS templates. The component name is derived from the class name.
For example, in the demo theme, create a template called test.htm with the following content. Then open the /test
URL.
See Also
License
This plugin is an official extension of the October CMS platform and is free to use if you have a platform license. See EULA license for more details.