Twig API
Class

Twig_Template

abstract class Twig_Template implements Twig_TemplateInterface

Default base class for compiled templates.

Methods

__construct(Twig_Environment $env)

Constructor.

string getTemplateName()

Returns the template name.

Twig_Environment getEnvironment()

Returns the bound environment for this template.

Twig_TemplateInterface|false getParent(array $context)

Returns the parent template.

isTraitable()

displayParentBlock(string $name, array $context, array $blocks = array())

Displays a parent block.

displayBlock(string $name, array $context, array $blocks = array())

Displays a block.

string renderParentBlock(string $name, array $context, array $blocks = array())

Renders a parent block.

string renderBlock(string $name, array $context, array $blocks = array())

Renders a block.

Boolean hasBlock(string $name)

Returns whether a block exists or not.

array getBlockNames()

Returns all block names.

array getBlocks()

Returns all blocks.

display(array $context, array $blocks = array())

Displays the template with the given context.

string render(array $context)

Renders the template with the given context and returns it as string.

static  clearCache()

This method is only useful when testing Twig.

Details

at line 33
public __construct(Twig_Environment $env)

Constructor.

Parameters

Twig_Environment $env A Twig_Environment instance

at line 45
abstract public string getTemplateName()

Returns the template name.

Return Value

string The template name

at line 50
public Twig_Environment getEnvironment()

Returns the bound environment for this template.

Return Value

Twig_Environment The current environment

at line 63
public Twig_TemplateInterface|false getParent(array $context)

Returns the parent template.

This method is for internal use only and should never be called directly.

Parameters

array $context

Return Value

Twig_TemplateInterface|false The parent template or false if there is no parent

at line 88
public isTraitable()

at line 103
public displayParentBlock(string $name, array $context, array $blocks = array())

Displays a parent block.

This method is for internal use only and should never be called directly.

Parameters

string $name The block name to display from the parent
array $context The context
array $blocks The current set of blocks

at line 126
public displayBlock(string $name, array $context, array $blocks = array())

Displays a block.

This method is for internal use only and should never be called directly.

Parameters

string $name The block name to display
array $context The context
array $blocks The current set of blocks

at line 153
public string renderParentBlock(string $name, array $context, array $blocks = array())

Renders a parent block.

This method is for internal use only and should never be called directly.

Parameters

string $name The block name to render from the parent
array $context The context
array $blocks The current set of blocks

Return Value

string The rendered block

at line 173
public string renderBlock(string $name, array $context, array $blocks = array())

Renders a block.

This method is for internal use only and should never be called directly.

Parameters

string $name The block name to render
array $context The context
array $blocks The current set of blocks

Return Value

string The rendered block

at line 198
public Boolean hasBlock(string $name)

Returns whether a block exists or not.

This method is for internal use only and should never be called directly.

This method does only return blocks defined in the current template or defined in "used" traits.

It does not return blocks from parent templates as the parent template name can be dynamic, which is only known based on the current context.

Parameters

string $name The block name

Return Value

Boolean true if the block exists, false otherwise

at line 213
public array getBlockNames()

Returns all block names.

This method is for internal use only and should never be called directly.

Return Value

array An array of block names

See also

hasBlock

at line 228
public array getBlocks()

Returns all blocks.

This method is for internal use only and should never be called directly.

Return Value

array An array of blocks

See also

hasBlock

at line 236
public display(array $context, array $blocks = array())

Displays the template with the given context.

Parameters

array $context An array of parameters to pass to the template
array $blocks An array of blocks to pass to the template

at line 244
public string render(array $context)

Renders the template with the given context and returns it as string.

Parameters

array $context An array of parameters to pass to the template

Return Value

string The rendered template

at line 451
static public clearCache()

This method is only useful when testing Twig.

Do not use it.