Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference in using .html.twig vs .twig

What is the difference between using .html.twig and .twig? Is there some kind of standard, is it framework specific, or is it just user preference?

like image 437
moe Avatar asked Sep 11 '25 07:09

moe


1 Answers

Under Symfony you have the possibility to deliver different formats automatically. So you can create files like test.json.twig, test.xml.twig for example. If you define all that extensions in your controller you can deliver all that formats under one action.

For example:

/**
 * @Route("/hello/{name}.{_format}", defaults={"_format"="html"}, name="_demo_hello")
 * @Template()
 */
public function helloAction($name) {
    return array('name' => $name);
}

Something like this. So you can use the format in your route to define the response format.

like image 64
René Höhle Avatar answered Sep 13 '25 22:09

René Höhle