Twig API
Class

Twig_Loader_String

class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface

Loads a template from a string.

This loader should only be used for unit testing as it has many limitations
(for instance, the include or extends tag does not make any sense for a string
loader).

When using this loader with a cache mechanism, you should know that a new cache
key is generated each time a template content "changes" (the cache key being the
source code of the template). If you don't want to see your cache grows out of
control, you need to take care of clearing the old cache file by yourself.

Methods

string getSource(string $name)

Gets the source code of a template, given its name.

boolean exists(string $name)

Check if we have the source code of a template, given its name.

string getCacheKey(string $name)

Gets the cache key to use for the cache for a given template name.

Boolean isFresh(string $name, timestamp $time)

Returns true if the template is still fresh.

Details

at line 31
public string getSource(string $name)

Gets the source code of a template, given its name.

Parameters

string $name The name of the template to load

Return Value

string The template source code

Exceptions

Twig_Error_Loader When $name is not found

at line 39
public boolean exists(string $name)

Check if we have the source code of a template, given its name.

Parameters

string $name The name of the template to check if we can load

Return Value

boolean If the template source code is handled by this loader or not

at line 47
public string getCacheKey(string $name)

Gets the cache key to use for the cache for a given template name.

Parameters

string $name The name of the template to load

Return Value

string The cache key

Exceptions

Twig_Error_Loader When $name is not found

at line 55
public Boolean isFresh(string $name, timestamp $time)

Returns true if the template is still fresh.

Parameters

string $name The template name
timestamp $time The last modification time of the cached template

Return Value

Boolean true if the template is fresh, false otherwise

Exceptions

Twig_Error_Loader When $name is not found