Symfony\Component\Templating\PhpEngine::render PHP Method

render() public method

Renders a template.
public render ( mixed $name, array $parameters = [] ) : string
$name mixed A template name or a TemplateReferenceInterface instance
$parameters array An array of parameters to pass to the template
return string The evaluated template as a string
    public function render($name, array $parameters = array())
    {
        $storage = $this->load($name);
        $key = md5(serialize($storage));
        $this->current = $key;
        $this->parents[$key] = null;

        // attach the global variables
        $parameters = array_replace($this->getGlobals(), $parameters);
        // render
        if (false === $content = $this->evaluate($storage, $parameters)) {
            throw new \RuntimeException(sprintf('The template "%s" cannot be rendered.', $this->parser->parse($name)));
        }

        // decorator
        if ($this->parents[$key]) {
            $slots = $this->get('slots');
            $this->stack[] = $slots->get('_content');
            $slots->set('_content', $content);

            $content = $this->render($this->parents[$key], $parameters);

            $slots->set('_content', array_pop($this->stack));
        }

        return $content;
    }

Usage Example

 public function send($email, $patchFiles)
 {
     $message = \Swift_Message::newInstance();
     $message->setSubject('Some code you are watching has been edited');
     $message->setFrom($this->from);
     $message->setTo($email);
     $message->setBody($this->view->render('htmlEmail', ['patchFiles' => $patchFiles]), 'text/html');
     //$message->addPart($body, 'text/plain');
     return $this->mailer->send($message);
 }
All Usage Examples Of Symfony\Component\Templating\PhpEngine::render