Score:0

theme_suggestions_html_alter not being picked

at flag

I'm trying to implement a custom template html--front--anonymous.html.twig which replaces html.html.twig. The suggestion is being showed, but its file is not being picked.

my_theme.theme

function MY_THEME_theme_suggestions_html_alter(&$suggestions, $variables) {
    if (\Drupal::currentUser()->isAnonymous()) { 
        if (\Drupal::service('path.matcher')->isFrontPage()) {
            $suggestions[] = 'html--front--anonymous';
        }
    } 
}

Screenshot that shows theme suggestions for html.html.twig Screenshot that shows the content of the folder layout, which contains html.html.twig and others

Score:1
cn flag

Suggestions need to use underscores rather than dashes:

$suggestions[] = 'html__front__anonymous';
Ricardo Castañeda avatar
at flag
I had tried that, but setting underscores in the filename too, which didn't work. Now I understand that the declaration of the suggestion must be with underscores, but the filename must be with dashes.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.