Download the PHP package mauricesnip/twig-elementary-bundle without Composer
On this page you can find all versions of the php package mauricesnip/twig-elementary-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mauricesnip/twig-elementary-bundle
More information about mauricesnip/twig-elementary-bundle
Files in mauricesnip/twig-elementary-bundle
Package twig-elementary-bundle
Short Description Build Twig components in the most elemental way, without a large footprint.
License MIT
Informations about the package twig-elementary-bundle
Twig Elementary Bundle
Build Twig components in the most elemental way, without a large footprint.
Heads up!
⚠️ This bundle is in early development stage and should not be used in production.
The examples below require Twig's
HtmlExtension to be installed. See
the documentation for
html_classes
on how to install this extension.
Installation
Run the following command to install this package with Composer:
Basic usage
Start by extending from
element-entry.html.twig,
which provides switching between
normal and
void elements
automatically.
Using the template above, the following include:
Will render:
Templates
element.html.twig
Renders a normal element.
Blocks
| Name | Description |
|---|---|
element |
Renders the full element. |
start_tag |
Renders the start tag with all of it's attributes. |
end_tag |
Renders the end tag. |
contents |
Renders the element's contents. |
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
attributes |
Object |
{} |
The HTML-attributes to render, eg.: { id: 'foo' }. |
contents |
String |
undefined |
The contents of the element. |
tag_name |
String |
span |
The HTML element's tag name, eg.: a, div or p. |
is_raw_contents |
Boolean |
undefined |
Whether to render raw contents or not. |
element-void.html.twig
Renders a void element. Extends
element.html.twig.
Blocks
| Name | Description |
|---|---|
element |
Renders the full element. |
start_tag |
Renders the start tag with all of it's attributes. |
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
attributes |
Object |
{} |
The HTML-attributes to render, eg.: { id: 'foo' }. |
tag_name |
String |
span |
The HTML element's tag name, eg.: a, div or p. |
element-entry.html.twig
Renders a normal or void element automatically.
For blocks and parameters, see the documentation for normal and void element
above. Extends
element.html.twig or
element-void.html.twig,
based on the provided tag_name.
Advanced usage
If you want to extend from your newly created component, be sure to allow for variables to receive values from their child components. Continuing on the basic usage example:
Variable overriding
Note that this also enables variable overriding for include or embed, for
example:
Will render:
attributes quirks
Be aware that overriding attributes.class will replace the entire class
attribute, since Twig does not support deep merge. Nor does merge concatenate
string values in any way. Thus, the following include:
Will render:
Hence classes|default in the advanced usage example for
appending classes to the final output. In this case, the following:
Will render:
Adding content
You can provide contents as a variable, which is mostly used for text
content. Markup is supported by setting is_raw_contents to true. See
documentation for element.html.twig.
Or, what you probably want most of the time, override the contents block.
Concrete example
Skeletons provide a base for components that come in many different flavors (or types) to extend from. Taking the advanced usage example one step further:
And a product card extending from the above skeleton:
This inherits all the way up to
element.html.twig, adding
features along the way. With that in mind, the following include:
Will render: