Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle][Twig] findAllTemplates not returning all templates #25811

Copy link
Copy link
Closed
@nicoschoenmaker

Description

@nicoschoenmaker
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.3

TL;DR; Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder doesn't find templates inside the templates/ folder.

This is because the TemplateFinder is unaware of the paths setting in the twig config. Changing the default directory structure in Symfony 4 means this setting is used more often now.

Related issue: #21035
Example usage in the wild: Tracker

Steps to reproduce:

composer create-project symfony/skeleton my_project
cd my_project
composer require templating twig frameworkbundle

Add to config/services.yaml

    App\Controller\MyController:
        arguments:
            $template_finder: "@templating.finder"
        public: true

Add to src/Controller/MyController.php

<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder;
use Symfony\Component\HttpFoundation\Response;

class MyController
{
    private $twig;
    private $template_finder;

    public function __construct(\Twig_Environment $environment, TemplateFinder $template_finder)
    {
        $this->twig = $environment;
        $this->template_finder = $template_finder;
    }

    public function listTemplates()
    {
        return new Response(
            $this->twig->render('templates.html.twig', ['templates' => $this->template_finder->findAllTemplates()])
        );
    }
}

Add to config/routes.yaml

index:
    path: /
    controller: App\Controller\MyController::listTemplates

Finally, add to templates/templates.html.twig

{% extends "base.html.twig" %}
{% block body %}
    {% for template in templates %}
        {{ template }}<br />
    {% endfor %}
{% endblock %}

Expected: base.html.twig and templates.html.twig part of the output
Result: Only files inside the FrameworkBundle and TwigBundle found.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.