Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm trying to create my own theme suggestion for a block (ds_4col). I created a function in mytheme.theme:
function mytheme_theme_suggestions_ds_4col_alter(array &$suggestions, array $variables) {
if(array_key_exists('#block_content', $variables['content']))
{
$suggestions[] = $variables['theme_hook_original'].'__block-content__'.preg_replace("/[^a-zA-Z0-9]+/", '_', strtolower($variables['content']['#block_content']->label()));
$suggestions = array_reverse($suggestions);
}
}
This works and I have these suggestions output:
<!-- FILE NAME SUGGESTIONS:
* ds-4col--block-content--department-links.html.twig
* ds-4col--block-content--2.html.twig
* ds-4col--block-content-four-links-equal-columns-full.html.twig
* ds-4col--block-content-four-links-equal-columns.html.twig
* ds-4col--block-content-full.html.twig
* ds-4col--block-content.html.twig
x ds-4col.html.twig
-->
However, when I place a twig in my templates directory with the file name 'ds-4col--block-content--department-links.html.twig', it is not being picked up and DS uses the default 'ds-4col.html.twig' in it's own directory...
Any help would be greatly appreciated. Thanks!
Comments
Comment #2
renaudcuny CreditAttribution: renaudcuny at OSCE: Organization for Security and Co-operation in Europe commentedHi,
I face a quite similar issue with suggestion for DS fields:
field--node--entityreference-field-field--node-ds-source-breadcrumb--aarhus-center.html.twig is not being picked-up, and Drupal uses field.html.twig from my theme.
Have you found any solution?
Comment #3
jonodunnett CreditAttribution: jonodunnett as a volunteer commentedAlso having the same issue with field templates. In fact I can use "field--ds.html.twig" suggestion, but the more specific templates are not picked up.
Comment #4
telegraph CreditAttribution: telegraph commentedI have not yet found a solution and ended up using one of the more basic template suggestions...
Comment #5
ABaier CreditAttribution: ABaier commentedI am facing something similar. The file name suggestions for a ds block field show up with a colon inside the pattern. I could not find a combination that got rendered.
That problem also seems to affect the class names, if you look at the missing separator inside "dynamic-block-field|node-article-video", where the colon probably gets stripped out by |clean_class:
Kint outputs the following:
file_name: "dynamic_block_field:node-article_video"
field_type: "ds"
Does somebody maybe know the correct file name pattern for this one? Thanks for your help!
Comment #6
renaudcuny CreditAttribution: renaudcuny at OSCE: Organization for Security and Co-operation in Europe commentedHi toni4i,
For the colon problem, see: https://www.drupal.org/node/2792811
Best,
Renaud
Comment #7
swentel CreditAttribution: swentel as a volunteer commentedSo suggestions for the entity templates should be fine now after #2802429: Display layout twig not overridable. got in (this is for the 8.x-3.x branch for D8 8.3.x).
Field templates will be further investigated in #2856283: Overridden twig field templates have empty content.