W3cubDocs

/Symfony 4.1

TwigEngine

class TwigEngine implements EngineInterface, StreamingEngineInterface

This engine knows how to render Twig templates.

Properties

protected $environment
protected $parser

Methods

__construct(Environment $environment, TemplateNameParserInterface $parser)
string render(string|TemplateReferenceInterface $name, array $parameters = array())

Renders a template.

stream(string|TemplateReferenceInterface $name, array $parameters = array())

Streams a template.

bool exists(string|TemplateReferenceInterface $name)

Returns true if the template exists.

bool supports(string|TemplateReferenceInterface $name)

Returns true if this class is able to render the given template.

Template load(string|TemplateReferenceInterface|Template $name)

Loads the given template.

Details

__construct(Environment $environment, TemplateNameParserInterface $parser)

Parameters

Environment $environment
TemplateNameParserInterface $parser

string render(string|TemplateReferenceInterface $name, array $parameters = array())

Renders a template.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance
array $parameters An array of parameters to pass to the template

Return Value

string The evaluated template as a string

Exceptions

RuntimeException if the template cannot be rendered

stream(string|TemplateReferenceInterface $name, array $parameters = array())

Streams a template.

The implementation should output the content directly to the client.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance
array $parameters An array of parameters to pass to the template

Exceptions

RuntimeException if the template cannot be rendered
LogicException if the template cannot be streamed

bool exists(string|TemplateReferenceInterface $name)

Returns true if the template exists.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance

Return Value

bool true if the template exists, false otherwise

Exceptions

RuntimeException if the engine cannot handle the template name

bool supports(string|TemplateReferenceInterface $name)

Returns true if this class is able to render the given template.

Parameters

string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance

Return Value

bool true if this class supports the given template, false otherwise

protected Template load(string|TemplateReferenceInterface|Template $name)

Loads the given template.

Parameters

string|TemplateReferenceInterface|Template $name A template name or an instance of TemplateReferenceInterface or Template

Return Value

Template

Exceptions

InvalidArgumentException if the template does not exist

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bridge/Twig/TwigEngine.html