Download the PHP package performing/twig-components without Composer
On this page you can find all versions of the php package performing/twig-components. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download performing/twig-components
More information about performing/twig-components
Files in performing/twig-components
Package twig-components
Short Description Twig components extension
License MIT
Homepage https://github.com/giorgiopogliani/twig-components
Informations about the package twig-components
Twig components extension
This is a PHP package for automatically create Twig components as tags. This is highly inspired from Laravel Blade Components.
Installation
You can install the package via Composer:
Configuration
This package should work anywhere where Twig is available.
To enable the package just pass your Twig environment object to the function and specify your components folder relative to your Twig templates folder.
Craft CMS
In Craft CMS you should do something like this.
The
if
statement ensure you don't get'Unable to register extension "..." as extensions have already been initialized'
as error.
Symfony
In Symfony you can do something like this.
OctoberCMS / WinterCMS
In OctoberCMS / WinterCMS you need to hook into event inside your plugin's boot method in order to access twig instance. Then you can use your plugin hint path to choose a views subfolder as component's folder.
Usage
es.
then in your htm files
Alle features like subfolders are supported, like will refer to
The components are just Twig templates in a folder of your choice (e.g. components
) and can be used anywhere in your Twig templates. The slot variable is any content you will add between the opening and the close tag.
Custom syntax
To reach a component you need to use custom tag x
followed by a :
and the filename of your component.
You can also pass any params like you would using an include
. The benefit is that you will have the powerful attributes
variable to merge attributes or to change your component behaviour.
To reach components that are in sub-folders you can use dot-notation syntax.
HTML syntax
The same behaviour can be obtained with a special HTML syntax. The previus component example can alse be used in this way.
Named slots
Also with the standard syntax.
Attributes
You can pass any attribute to the component in different ways. To interprate the content as Twig you need to prepend the attribute name with a :
but it works also in other ways.
Twig Namespaces
In addition to the specified directory, you can also reference components from a Twig namespace by prepending the namespace and a :
to the component name. With a namespace defined like so:
Components can be included with the following:
Dynamic Components
Sometimes you may need to render a component but not know which component should be rendered until runtime. In this situation, you may use the built-in dynamic-component component to render the component based on a runtime value or variable:
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Testing
License
The MIT License (MIT). Please see License File for more information.