In addition to various precisely defined variables, many components will have a flexible region where arbitrary content can be rendered. We might think of such a region as a container, niche, or slot. There are several possible ways to render content into such niches. For consistency, it would be useful to have a standard approach.
Examples from the Bulma CSS framework, integrated in the Bulma Components module:
On the Drupal side, there are various types of data we might want to pass into such a niche. Maybe it's render arrays. Maybe it's Twig templates and accompanying variables. Maybe it's one or more embedded components.
Here are some concrete examples from .
So far in Bulma Components, we're handling these niches with a set of three variables--or, really, up to three, since the approach has not yet been consistently used. But let's take the box component (`bbox`) as an example.
The component variables include a set of three variables that can be used to add content to the niche. Two are "common variables" (shared across multiple components) and so defined elsewhere, in this case in bulma_components.component_schema.yml
. Here's the expanded version:
content:
label: 'Content to add to the box'
nullable: true
type: string
templates:
label: 'Templates to be included'
nullable: true
type: component_sequence
sequence:
label: 'Template'
type: component_template
components:
label: 'Components to be included'
nullable: true
type: component_sequence
sequence:
label: 'Component'
type: component_component
And here's the relevant snippet from the corresponding box component Twig template:
{% block content %}
{{ content }}
{% for template in templates %}
{{ template|raw }}
{% endfor %}
{% for component in components %}
{{ component|raw }}
{% endfor %}
{% endblock content %}
And here's an example of feeding in the data, in this case from a sample Twig template:
{%
set box = {
content: 'My box content',
components: [
{
component_type: 'bbutton',
variables: {
label: 'My button',
size: 'is-medium',
color: 'is-danger',
}
}
]
}
%}
{{ include('@bulma_components/elements/box/box.html.twig', box) }}
To summarize this approach, it's:
Use a standard set of three variables, handling (a) arbitrary content such as render arrays, (b) templates to embed, and (c) other components to embed.
This kinda sorta works, but could use more though and review before anything is brought into Component Schema as a standard approach.
Active
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.