SSTemplateEngine
class SSTemplateEngine implements TemplateEngine, Flushable (View source)
Parses template files with an *.ss file extension, or strings representing templates in that format.
In addition to a full template in the templates/ folder, a template in
templates/Content or templates/Layout will be rendered into $Content
and
$Layout
, respectively.
A single template can be parsed by multiple nested SSTemplateEngine instances
through $Layout
/$Content
placeholders, as well as <% include MyTemplateFile %>
template commands.
Caching
Compiled templates are cached, usually on the filesystem. If you put ?flush=1 on your URL, it will force the template to be recompiled.
Traits
A class that can be instantiated or replaced via DI
Provides extensions to this object to integrate it with standard config API methods.
Config options
global_key | string | Default prepended cache key for partial caching |
Properties
protected static | array | $topLevel | List of models being processed |
Methods
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
Execute the given template, passing it the given data.
Clears all parsed template files in the cache folder.
Check if there is a template amongst the template candidates that this rendering engine can use.
Render the template string.
Render the template which was selected during instantiation or which was set via setTemplate().
Set the template which will be used in the call to render()
Set the cache object to use when storing / retrieving partial cache blocks.
Get the cache object to use when storing / retrieving partial cache blocks.
An internal utility function to set up variables in preparation for including a compiled template, then do the include
Get the appropriate template to use for the named sub-template, or null if none are appropriate
Parse given template contents
Details
static Injectable
create(mixed ...$args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
__construct(string|array $templateCandidates = [])
Instantiate a TemplateEngine
static string
execute_template(array|string $template, ViewLayerData $data, array $overlay = [], ScopeManager|null $scope = null)
Execute the given template, passing it the given data.
Used by the <% include %> template tag to process included templates.
static
flush()
Triggered early in the request when someone requests a flush.
static void
flushTemplateCache(bool $force = false)
Clears all parsed template files in the cache folder.
static void
flushCacheBlockCache(bool $force = false)
Clears all partial cache blocks.
bool
hasTemplate(string|array $templateCandidates)
Check if there is a template amongst the template candidates that this rendering engine can use.
string
renderString(string $template, ViewLayerData $model, array $overlay = [], bool $cache = true)
Render the template string.
Doesn't include normalisation such as inserting js/css from Requirements API - that's handled by SSViewer.
string
render(ViewLayerData $model, array $overlay = [], ScopeManager|null $scope = null)
Render the template which was selected during instantiation or which was set via setTemplate().
Doesn't include normalisation such as inserting js/css from Requirements API - that's handled by SSViewer.
TemplateEngine
setTemplate(string|array $templateCandidates)
Set the template which will be used in the call to render()
SSTemplateEngine
setParser(TemplateParser $parser)
Set the template parser that will be used in template generation
TemplateParser
getParser()
Returns the parser that is set for template generation
SSTemplateEngine
setPartialCacheStore(CacheInterface $cache)
Set the cache object to use when storing / retrieving partial cache blocks.
CacheInterface
getPartialCacheStore()
Get the cache object to use when storing / retrieving partial cache blocks.
protected string
includeGeneratedTemplate(string $cacheFile, ViewLayerData $model, array $overlay, array $underlay, ScopeManager|null $inheritedScope = null)
An internal utility function to set up variables in preparation for including a compiled template, then do the include
protected array|null
getSubtemplateFor(string $subtemplate)
Get the appropriate template to use for the named sub-template, or null if none are appropriate
protected string
parseTemplateContent(string $content, string $template = "")
Parse given template contents