madeyourday/contao-rocksolid-custom-elements
Adds RockSolid Custom Elements to Contao, letting you create and manage custom content elements with flexible fields and templates. Install via Composer and follow the official English/German documentation for setup and usage.
composer require madeyourday/contao-rocksolid-custom-elements
config/autoload.php:
'rocksolid_custom_elements' => ['enabled' => true],
resources/contao/custom_elements/my_element.yaml):
name: "My Custom Element"
type: "text"
template: "ce_my_element"
fields:
- name: "headline"
type: "text"
label: "Headline"
config/autoload.php:
'rocksolid_custom_elements' => [
'enabled' => true,
'elements' => [
'my_element' => 'path/to/my_element.yaml',
],
],
templates/ce_my_element.html5):
<div class="my-element">
<h2>{{ element.headline }}</h2>
{{ element.content|raw }}
</div>
Use the package to replace generic Contao content elements (e.g., text, html) with domain-specific components (e.g., testimonial, pricing_table). For example:
name, role, quote, and avatar.allowedIn in the YAML config.name: "Pricing Table"
type: "table" # Supports: text, table, list, group, etc.
template: "ce_pricing_table"
fields:
- name: "title"
type: "text"
label: "Table Title"
- name: "items"
type: "list"
label: "Pricing Items"
fields:
- name: "name"
type: "text"
label: "Plan Name"
- name: "price"
type: "text"
label: "Price"
default: "$0"
extends:
extends: "base_fields.yaml"
dependsOn:
fields:
- name: "show_cta"
type: "checkbox"
label: "Show CTA Button"
- name: "cta_text"
type: "text"
label: "CTA Text"
dependsOn: "show_cta" # Hidden unless checkbox is checked
validate callbacks in PHP for complex rules.type: "group"
fields:
- name: "tabs"
type: "list"
label: "Tabs"
fields:
- name: "title"
type: "text"
- name: "content"
type: "html"
ce_base.html5) for shared markup.tl_content).palettes to organize fields logically:
palettes:
default: "title;items"
templates/ce_* for custom styling.{{ element|rocksolid_custom_elements }} filter for dynamic content.rocksolid_custom_elements.load or rocksolid_custom_elements.save for custom logic.assets key in YAML.Template Paths:
ce_<element_name>.html5 and placed in templates/.template key in YAML matches the filename exactly.Field Dependencies:
dependsOn does not work with type: "hidden" fields.type: "checkbox" with eval: "tl_class=invisible" for hidden-but-conditional fields.Contao Version Mismatches:
v2.3.x for Contao <4.9 or 4.9–5.6.php bin/contao-requirements-check after updates.Nested List Quirks:
type: "list" fields include a unique name and proper fields structure.Backend Route Conflicts:
rocksolid_custom_elements_ (e.g., rocksolid_custom_elements.my_element).config/localconfig.php:
$GLOBALS['TL_DEBUG'] = true;
tl_content fields:
\System::log(\Database::getInstance()->prepare("SELECT * FROM tl_content WHERE type='my_element'")->execute()->fetchAll(), 'DEBUG');
php bin/contao-console cache:clear
Custom Widgets:
\RockSolid\CustomElementsBundle\Widget\AbstractWidget for new field types.ContaoCoreBundle\Framework\Widget\WidgetInterface for full compatibility.Validation Hooks:
RockSolid\CustomElementsBundle\Event\ValidateElementEvent for pre-save checks:
$eventDispatcher->addListener(
'rocksolid_custom_elements.validate.my_element',
function ($event) {
if (empty($event->getData()['headline'])) {
$event->setError('Headline is required.');
}
}
);
Twig Extensions:
rocksolid_custom_elements.twig:
{% macro render_element(element) %}
{{ include('ce_' ~ element.type ~ '_' ~ element.template) with {
'element': element
}}}
{% endmacro %}
Asset Bundling:
AssetManager:
$container->bind('rocksolid_custom_elements.asset_manager', function () {
return new \App\CustomAssetManager();
});
onload callbacks (run async if possible).eval: "mandatory=false".{% cache %} for static elements.composer require contao/core:4.9.* and the package’s v2.3.x branch.v2.3.x to avoid widget issues.text, textarea, select) now work seamlessly.AbstractWidget and implementing WidgetInterface.How can I help you explore Laravel packages today?