1

I updated my project to Symfony4. When I go to some page with a form I have this error appearing :

Unable to find template "StarRatingBundle::rating.html.twig" 
(looked into: /templates, /templates, \vendor\symfony\twig-bridge/Resources/views/Form).

I use blackknight467/star-rating-bundle a bundle which provides a twig extension to have a star rating system. The template in the error is located in this bundle Resources/views folder.

Twig.yaml :

twig:
    paths: ['%kernel.project_dir%/templates']
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    form_themes:
        - 'Form/fields.html.twig'
tereško
  • 58,060
  • 25
  • 98
  • 150
Kristen Joseph-Delaffon
  • 1,261
  • 2
  • 17
  • 37
  • Wich is version of your Symfony? – Imanali Mamadiev Feb 25 '18 at 14:38
  • I updated to Symfony4 recently – Kristen Joseph-Delaffon Feb 25 '18 at 14:39
  • 3
    The use of colons in twig template paths is discouraged. You could use them with the proper configuration changes but it's best to use what is known as twig namespaces. Somthing like '@StarRating/rating.html.twig' If you are unsure of exactly where @StarRating points to then use "bin/console debug:twig" [More Details](https://stackoverflow.com/questions/47832977/symfony-3-4-use-view-inside-my-bundle/47835716#47835716) – Cerad Feb 25 '18 at 14:45
  • The real problem is that in the page where the error apears, I don't use this template and I can't find from where the error come. The only use of `StarRatingBundle::rating.html.twig` in my code is in the bundle source. I even tried to change it in vendor with what you said but the error remains. – Kristen Joseph-Delaffon Feb 25 '18 at 15:17
  • 1
    @KristenJoseph-Delaffon In that case, scroll down to the bottom of the linked answer and adjust your framework's config.yaml file. You basically need to enable the Symfony templating component to get the bundle name mapping stuff to work. Be a bit careful, that fact that the StarRatingBundle still uses the old style format implies it has not been updated for 4.0. Might encounter other issues as well. – Cerad Feb 25 '18 at 15:41
  • Thank you for your help. It's working now. I know that this bundle has not been updated and I doubt it will be (last update in 2014). I'll try to update it myself when I have some time. – Kristen Joseph-Delaffon Feb 25 '18 at 16:04
  • Nothing says thanks like an up vote. – Cerad Feb 25 '18 at 16:10

2 Answers2

1

Symfony 4+ does not support “x:x:x.html.twig” notation. You need to install composer require templating

then activate it in your framework.yaml by adding

templating: engines: ['twig'].

Files > Invalidate caches & restart. This should allow Symfony to find your templates.

Thabo Moyo
  • 183
  • 1
  • 7
0

I struggled with the issue when creating a symfony 5 bundle. Make sure you keep your twig templates in <project-folder>/Resources/views folder. In your Controller, using HelloworldController as an example:

`<?php
    namespace Example\HelloBundle\Controller;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;

    class HelloController extends AbstractController
    {
        public function index(): Response
        {
            return $this->render('@<BundleName>/hello/index.html.twig',           [
            'controller_name' => 'HelloController',
            ]);
        }
    }

is the name of your bundle without the bundle suffix. For example if you registered your bundle as Example\HelloBundle\ExampleHelloBundle::class => ['all' => true], in Bundles.php then <BundleName> is ExampleHello

broswilli
  • 307
  • 2
  • 5