Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve local file path from Twig template name

Tags:

twig

symfony

What are the programmatic steps to turn this string:

AcmeProjectBundle::home.html.twig

into this?

/path/Symfony/src/Acme/ProjectBundle/Resources/views/home.html.twig
like image 812
ojreadmore Avatar asked Feb 17 '12 14:02

ojreadmore


1 Answers

If you want to retrieve path from a controller you can use this code:

$parser = $this->container->get('templating.name_parser');
$locator = $this->container->get('templating.locator');

$path = $locator->locate($parser->parse('AcmeProjectBundle::home.html.twig'));

For more info take a look at code of:

  • Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser::parse
  • Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::locate
like image 73
Molecular Man Avatar answered Nov 10 '22 07:11

Molecular Man