[2.0.0-beta4] Replace component() function by native Twig mechanisms?

Created on 24 May 2024, 6 months ago
Updated 20 September 2024, about 2 months ago

Problem/Motivation

In UI Patterns, we were using pattern() custom Twig function, with those parameters:

  • id: string
  • fields (slots) & settings (props): associative array
  • variant: string
pattern('nav_item', {
    'attributes': attributes,
    'active': is_active,
    'link': link
})

SDC community is currently using existing Twig mechanisms.

embed tag:

{% embed 'governor:usa_accordion_item' with {
  attributes,
  open: (block_attributes.open) ? 'true' : 'false',
  heading: block_attributes.heading,
  content: block_content,
} only %}
  {% block content %}
    {{ content }}
  {% endblock %}
{% endembed %}

include function or include tag :

  {{ include('governor:usa_pagination', {
    pages: items.pages,
    first: items.first,
    last: items.last,
    previous: items.previous,
    next: items.next,
    ellipsis_previous: ellipses.previous ? true : false,
    ellipsis_next: ellipses.next ? true : false,
    current: current,
    last_page: last_page,
  }, with_context = false) }}

{% include 'kinetic:form' with { attributes, children } %}

It is not OK because they are doing template to template calls, not template to components. They don't trigger the render element and the related processing.

In UI Patterns 2, we have currently implemented a custom component() Twig function, with those parameters:

  • component: string
  • slots: associative array
  • props: associative array
{{ component('sdc_examples:my-button', { text: 'Click Me'}, { iconType: 'external' }) }}

It works well, but it is a custom fucntion, too specific.

Proposed resolution

Is it specify to alter the behaviour of embed tag and/or include tag and/or include function to make it pass through the SDC render element instead of calling directly the template? A bit like what Core is already doing with print nodes: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

Will it not break the existing SDC themes which have a "liberal" use of SDC components (there are errors in defintiions, but they don't trigger them because they do template to template calls)?

Can we remove component() function? Can we convert pattern() to one of this Twig native tags/functions?

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024