Nickolaus
Nickolaus

Reputation: 4835

Symfony template rendering syntax style

A question which I am asking myself since a while:

Can anyone tell me if there is a difference in rendering a template with
@-annotation or in colon-style:

@Acme/AcmeBundle/Default/index.html.twig
Acme:AcmeBundle:Default:index.html.twig

and if there is a difference what is it,
if not which is the newer/proper one and should be used accordingly?

Upvotes: 2

Views: 407

Answers (1)

vijaykumar
vijaykumar

Reputation: 4806

Both namespaced templates and traditional template will work as expected in views but it wont work in controllers. Please check here

    // namespaced templates will no longer work in controllers
    $this->render('@App/Default/index.html.twig');

    // you must use the traditional template notation
    $this->render('AppBundle:Default:index.html.twig');

{# inside a Twig template, namespaced templates work as expected #}
{{ include('@App/Default/index.html.twig') }}

{# traditional template notation will also work #}
{{ include('AppBundle:Default:index.html.twig') }}

The namespaced syntax is faster.

Please refer this for more info

Upvotes: 4

Related Questions