0

I have installed Bootstrap and the Radix theme, and created a sub-theme, which is all working OK. But I am unable to get some of my twig files to override the base theme twig files...

The file themes/custom/mytheme/templates/page/page.html.twig contains: {% embed '@radix/navbar/navbar.twig' with {

I would like to create a navbar.twig in my subtheme and use that instead of the standard radix one. Changes I make to themes/contrib/radix/src/components/navbar/navbar.twig will show up on my site (as this is what the embed refers to), but changes to themes/custom/mytheme/src/components/navbar/navbar.twig do not.

How can I change that embed line so that it includes the subtheme twig rather than the base? It's some kind of twig namespace? I have not been able to figure out where it is defined.

5
  • You can't. Create your own page.html.twig instead and use {% embed '@my_subtheme/navbar/... %} in there.
    – Hudri
    Commented Sep 20, 2019 at 12:48
  • And yes, @radix is a namespace. Drupal provides a Twig @namespace for every theme and every module.
    – Hudri
    Commented Sep 20, 2019 at 12:53
  • @Hudri where is the my_subtheme namespace defined? Because when I change it from radix to mytheme I just get "The website encountered an unexpected error. Please try again later." I have used the directory name (which is "mytheme"), and the name in mytheme.info.yml after name: (which is MyTheme) and neither worked
    – Innovine
    Commented Sep 20, 2019 at 13:01
  • Use the machine name = directory of your subtheme. If your theme's machine name is johndoe, use @johndoe. Only lowercase, digits and underlines are allowed for machine names. The Twig file must be placed below the templates subdir, but do not include templates/ in the embed string
    – Hudri
    Commented Sep 20, 2019 at 13:10
  • I got it now, thanks! You should post as an answer.
    – Innovine
    Commented Sep 20, 2019 at 13:18

1 Answer 1

1

You can't. Create your own page.html.twig instead and use {% embed '@my_subtheme/navbar/... %} in there.

Use the machine name == directory of your subtheme for @my_subtheme. Only lowercase, digits and underlines are allowed for machine names. The Twig file must be placed below the templates subdir, but do not include templates/ in the embed string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.