bolt: [BUG] Overriding extension templates inside a theme breaks when template_directory is configured

A Bolt extension can add a template path to Bolt’s twig for it’s own template files. If you then use the same template/folder names inside your theme, you can override the extensions template (provided it’s not added with the prepend option. This breaks, if a theme does use a sub folder for it’s twig templates via the configuration option template_directory inside it’s theme.yml.

Hint: you can workaround this problem by including the same template directory as configured in your theme.yml in your extensions template paths. This implies that whatever magic makes Bolt prefix the template_directory for a theme’s templates does not apply them anywhere else.

Use Case: Let’s assume you have an extension that can render a HTML block for an image. The extension has it’s own template in a folder <extension>/templates/myimage.twig and adds the folder via

protected function registerTwigPaths(){
    return ['templates'];
}

Your theme also has a file myimage.twig. Now the template engine will use your theme’s template and not the one from the extension as it has higher priority.

If you now store the file in a subfolder templates in your theme and configure the option template_directory: templates nin your theme.yml, this override process fails.

Expected behaviour: The template override mechanism of twig works, no matter where your template base folder is, as long as files and folders are exactly the same (which is the normal behaviour of twig).

Details

  • Relevant Bolt Version: 3.2
  • Install type: Composer install
  • PHP version: 5.5
  • Used web server: Apache

Reproduction

See Use Case above. you need an extension, that provides a template and does not specify the prepend option. Create a theme that uses this extensions template and does not have a subfolder for it’s templates.

Test: Website shows extensions template OK

Now copy the extensions template to your theme’s base folder. Modify it’s contents.

Test: Website shows themes template OK

Now move the theme’s templates into a subfolder and configure this subfolder in your theme.yml.

Test: Website shows extensions template Fail

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Hurray! I finally got it all working.

The bad news is: manually adding the theme folder (that was the workaround for Bolt 3.2) crashes as the system cant find the template.

The good news is: We dont care, because that was a dirty hack anyways and the system works fine with the correct paths now, without the theme folder.

In short: many thanks. Please close.

{{ global.request.get('foo') }}