Skip to content

[Twig] Allow filtering for file extensions in template paths #41950

@crtl

Description

@crtl

Description
When providing paths configuration for twig templates all files in those paths are handled as templates which leads to cache:warmup crashes when paths contain non twig templates because of invalid syntax.

Example

# twig.yaml
twig:
  extensions:
    - .html.twig
    - .html

Context
I have to serve an angular app through symfony server because the source code should be protected by security firewall.
Angular project is located in separate directory.

To deploy into Symfony I:

  • build angular app
  • copy build output to symfony project
  • have twig path configured to target build output based on environment
# twig.yaml
twig:
  paths:
    "angular/webapp/dev": "webapp"

Then in my controller I can render app template and inject configuration:

// controller pseudo code
class Controller {
  public function index() {
    return $this->render("webapp/index.html", $data);
  }
}

This worked in Symfony 4 but after upgrading to Symfony 5 i encounter template syntax error on cache:warmup and :clean because angular directory contains javascript files which are not valid twig templates.

An option to filter files by extension would solve this problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions