Symfony\Bundle\FrameworkBundle\Templating\TemplateReference::getPath PHP Method

getPath() public method

Returns the path to the template - as a path when the template is not part of a bundle - as a resource when the template is part of a bundle
public getPath ( ) : string
return string A path to the template or a resource
    public function getPath()
    {
        $controller = str_replace('\\', '/', $this->get('controller'));

        $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');

        return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
    }

Usage Example

 /**
  * Collects data for the given Request and Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An Exception instance
  *
  * @api
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $messages = array();
     $content = $response->getContent();
     $path = '';
     $fileContent = '';
     $template = $request->attributes->get('_template');
     if (is_null($template)) {
         $templateName = $request->attributes->get('template');
         list($front, $format, $engine) = explode('.', $templateName);
         $templateParts = explode(":", $front);
         $template = new TemplateReference($templateParts[0], $templateParts[1], $templateParts[2], $format, $engine);
     }
     if ($template instanceof TemplateReference) {
         $locale = $request->attributes->get('_locale', $request->getLocale());
         $catalogue = new MessageCatalogue($locale);
         $path = $template->getPath();
         /**
          * Check if $path is a resource
          */
         if (strstr($path, '@')) {
             $kernel = $this->container->get('kernel');
             $path = $kernel->locateResource($path);
             $fileContent = file_get_contents($path);
         }
         $this->twigExtractor->extractTemplate($path, $catalogue);
         $messages = $catalogue->all();
     }
     $this->data = array('content' => $content, 'file_content' => $fileContent, 'messages' => $messages, 'path' => $path);
 }
All Usage Examples Of Symfony\Bundle\FrameworkBundle\Templating\TemplateReference::getPath