- Configuration
- Use template variables
- Support own extensions
- Import / Export
- Bundle-Configurations
- Migration
As Twig is not yet fully supported (Contao ^5.1), this feature will only work with Legacy-Templates)
https://docs.contao.org/dev/framework/templates/legacy/
To use legacy-templates (html5) in contao ^5.1, you can force this by overwriting config.php in "/contao/config/config.php".
<?php
$GLOBALS['TL_CTE']['texts']['code'] = \Contao\ContentCode::class;
$GLOBALS['TL_CTE']['texts']['headline'] = \Contao\ContentHeadline::class;
$GLOBALS['TL_CTE']['texts']['html'] = \Contao\ContentHtml::class;
$GLOBALS['TL_CTE']['texts']['list'] = \Contao\ContentList::class;
$GLOBALS['TL_CTE']['texts']['text'] = \Contao\ContentText::class;
$GLOBALS['TL_CTE']['texts']['table'] = \Contao\ContentTable::class;
$GLOBALS['TL_CTE']['links']['hyperlink'] = \Contao\ContentHyperlink::class;
$GLOBALS['TL_CTE']['links']['toplink'] = \Contao\ContentToplink::class;
$GLOBALS['TL_CTE']['media']['image'] = \Contao\ContentImage::class;
$GLOBALS['TL_CTE']['media']['gallery'] = \Contao\ContentGallery::class;
$GLOBALS['TL_CTE']['media']['youtube'] = \Contao\ContentYouTube::class;
$GLOBALS['TL_CTE']['media']['vimeo'] = \Contao\ContentVimeo::class;
If the checkbox Use as template variable
is set, these are not automatically passed to the CSS class of the corresponding element but are available in the template.
To access the variables, we can access the corresponding class collection via the styleManager
object.
Return selected CSS classes of a category or a specific group
Method arguments:
Argument | Type | Description |
---|---|---|
identifier | string |
Category identifier |
groups (Optional) | null׀array |
Group aliases |
Example:
// Return of all selected CSS classes of a category
$this->styleManager->get('myCategoryIdentifier');
// Return of all selected CSS classes in specific groups of a category
$this->styleManager->get('myCategoryIdentifier', ['alias1', 'alias2']);
Different from the get
method, you can specify your own output format and a predefined or custom method to validate the output.
Arguments of the prepare
method:
Argument | Type | Description |
---|---|---|
identifier | string |
Category identifier |
groups (Optional) | null׀array |
Group aliases |
Arguments of the format
method:
Argument | Type | Description |
---|---|---|
format | string |
The format parameter must contain a format string valid for sprintf (PHP: sprintf)) |
method (Optional) | string |
A method name to manipulate the output |
Example:
// Return of all selected CSS classes of a category within a class attribute
$this->styleManager->prepare('myCategoryIdentifier')->format('class="%s"');
// Additional classes are often appended to an existing class attribute. In this case, unnecessary if-else statements can be avoided by appending a space character if a value exists.
$this->styleManager->prepare('myCategoryIdentifier')->format(' %s');
// Return of all selected CSS classes in specific group of a category as json within a data attribute
$this->styleManager->prepare('myCategoryIdentifier', ['alias1'])->format("data-slider='%s'", 'json');
Returns a JSON object using the alias and value (e.g. {"alias1":"my-class-1","alias2":"my-class-2"}
)
To add your own methods you can use the styleManagerFormatMethod
hook:
function customFormatMethod(string $format, string $method, Styles $context): string
{
// Custom stuff
}