1

I dont understand what does @ do in this routing? exemple:

{% extends "@User/Default/index.html.twig" %}

i am trying to find the file that is extended but unable to do so.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
Masmoudi
  • 123
  • 1
  • 9
  • 2
    If I'm not wrong, `@` stands for `bundle` which means that twig should extend your template from `UserBundle/Default/index.html.twig`. – GasKa Dec 01 '19 at 16:13
  • 2
    The @ is the symbol used by twig to indicate a namespace. In your question, the namespace is '@User'. Somewhere in your configuration, '@User' is mapped to a specific directory. You can use "bin/console debug:twig" to see your namespace mapping. [More info here](https://symfony.com/doc/current/templates.html#template-namespaces). – Cerad Dec 01 '19 at 16:17
  • @Cerad you probably want to write that as an answer? ;) – Nico Haase Dec 02 '19 at 07:58
  • @NicoHaase Not really. Sames question has been asked a dozen time. Just not a big fan of down voting and voting to close. A quick comment was all that was needed. – Cerad Dec 02 '19 at 12:29

2 Answers2

1

Thanks to the comment left by @Cerad I found it using: bin/console debug:twig

@User src\UserBundle/Resources/views\

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Masmoudi
  • 123
  • 1
  • 9
0

Usually, when you refer to a template, you'll use the MyBundle:User:index.html.twig format. Twig also natively offers a feature called "namespaced paths", and support is built-in automatically for all of your bundles.

Take the following paths as an example:

{% extends "MyBundle:User:layout.html.twig" %}

With namespaced paths, the following works as well:

{% extends "@App/layout.html.twig" %}

Both paths are valid and functional by default in Symfony.

Naruto Uzumaki
  • 198
  • 2
  • 5
  • 11
  • Not quite. The first approach is no longer supported out of the box (since 3.4 or so). You would need to install a templating component and do some configuring. [Discussion](https://stackoverflow.com/questions/47832977/symfony-3-4-use-view-inside-my-bundle/47835716#47835716). Plus, the use of an AppBundle has pretty much gone away. Your second example is really the only current choice. And you really did not address the "how to find the template file" portion of the question. – Cerad Dec 02 '19 at 12:40