SSViewerProxy
class SSViewerProxy extends SSViewer (View source)
The template parser proxy will monitor the templates that are used during a page request. Since the use of the template parser is behind cache checks, this will only execute during a cache flush.
Traits
Provides extensions to this object to integrate it with standard config API methods.
A class that can be instantiated or replaced via DI
Constants
DEFAULT_THEME |
Identifier for the default theme |
PUBLIC_THEME |
Identifier for the public theme |
Config options
themes | string | A list (highest priority first) of themes to use Only used when $theme_enabled is set to TRUE. |
from SSViewer |
theme | string | The used "theme", which usually consists of templates, images and stylesheets. |
from SSViewer |
theme_enabled | bool | Use the theme. Set to FALSE in order to disable themes, which can be useful for scenarios where theme overrides are temporarily undesired, such as an administrative interface separate from the website theme. |
from SSViewer |
global_key | string | Default prepended cache key for partial caching |
from SSViewer |
source_file_comments | bool | from SSViewer | |
rewrite_hash_links | bool | Set if hash links should be rewritten |
from SSViewer |
Properties
protected static | array | $current_themes | Overridden value of $themes config |
from SSViewer |
protected static | bool | $current_rewrite_hash_links | Overridden value of rewrite_hash_links config |
from SSViewer |
protected | bool|null | $rewriteHashlinks | Instance variable to disable rewrite_hash_links (overrides global default) Leave null to use global state. |
from SSViewer |
protected static | array | $topLevel | List of items being processed |
from SSViewer |
protected | array | $templates | List of templates to select from |
from SSViewer |
protected | string | $chosen | Absolute path to chosen template file |
from SSViewer |
protected | array | $subTemplates | Templates to use when looking up 'Layout' or 'Content' |
from SSViewer |
protected | bool | $includeRequirements | from SSViewer | |
protected | TemplateParser | $parser | from SSViewer | |
protected | CacheInterface | $partialCacheStore | from SSViewer | |
protected static | array | $allTemplates | Tracks all templates used in the current request |
|
protected static | bool | $cached | Whether the class has been used, meaning whether the page has been cached |
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Create a template from a string instead of a .ss file
Assign the list of active themes to apply.
Add to the list of active themes to apply
Traverses the given the given class context looking for candidate template names which match each item in the class hierarchy. The resulting list of template candidates may or may not exist, but you can invoke {SSViewer::chooseTemplate} on any list to determine the best candidate based on the current themes.
Check if rewrite hash links are enabled on this instance
Set if hash links are rewritten for this instance
Get default value for rewrite hash links for all modules
Set default rewrite hash links
Find the template to use for a given list
Returns true if at least one of the listed templates exists.
Call this to disable rewriting of links. This is useful in Ajax applications.
No description
Clears all parsed template files in the cache folder.
Clears all partial cache blocks.
Set the cache object to use when storing / retrieving partial cache blocks.
Get the cache object to use when storing / retrieving partial cache blocks.
Flag whether to include the requirements in this response.
An internal utility function to set up variables in preparation for including a compiled template, then do the include
Overloaded to track all templates used in the current request
Get the appropriate template to use for the named sub-template, or null if none are appropriate
Execute the given template, passing it the given data.
Execute the evaluated string, passing it the given data.
Parse given template contents
Returns the filenames of the template that will be rendered. It is a map that may contain 'Content' & 'Layout', and will have to contain 'main'
Return an appropriate base tag for the given template.
Get the templates used in the current request and the number of times they were called
Details
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
stat(string $name)
deprecated
deprecated
Get inherited config value
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
$this
set_stat(string $name, mixed $value)
deprecated
deprecated
Update the config value for a given property
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).
__construct(string|array $templates, TemplateParser $parser = null)
No description
static
flush()
Triggered early in the request when someone requests a flush.
static SSViewer
fromString(string $content, bool|void $cacheTemplate = null)
Create a template from a string instead of a .ss file
static
set_themes(array $themes = [])
Assign the list of active themes to apply.
If default themes should be included add $default as the last entry.
static
add_themes(array $themes = [])
Add to the list of active themes to apply
static array
get_themes()
Get the list of active themes
static
set_theme(string $theme)
deprecated
deprecated
No description
static array
get_templates_by_class(string|object $classOrObject, string $suffix = '', string $baseClass = null)
Traverses the given the given class context looking for candidate template names which match each item in the class hierarchy. The resulting list of template candidates may or may not exist, but you can invoke {SSViewer::chooseTemplate} on any list to determine the best candidate based on the current themes.
static ViewableData
topLevel()
Get the current item being processed
bool
getRewriteHashLinks()
Check if rewrite hash links are enabled on this instance
$this
setRewriteHashLinks(bool $rewrite)
Set if hash links are rewritten for this instance
static bool
getRewriteHashLinksDefault()
Get default value for rewrite hash links for all modules
static
setRewriteHashLinksDefault(bool $rewrite)
Set default rewrite hash links
setTemplate(string|array $templates)
No description
static string
chooseTemplate(array|string $templates)
Find the template to use for a given list
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
static bool
hasTemplate(array|string $templates)
Returns true if at least one of the listed templates exists.
$this
dontRewriteHashlinks()
Call this to disable rewriting of links. This is useful in Ajax applications.
It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process();
string
exists()
No description
static string
getTemplateFileByType(string $identifier, string $type = null)
No description
static
flush_template_cache(bool $force = false)
Clears all parsed template files in the cache folder.
Can only be called once per request (there may be multiple SSViewer instances).
static
flush_cacheblock_cache(bool $force = false)
Clears all partial cache blocks.
Can only be called once per request (there may be multiple SSViewer instances).
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.
includeRequirements(bool $incl = true)
Flag whether to include the requirements in this response.
protected string
includeGeneratedTemplate(string $cacheFile, ViewableData $item, array $overlay, array $underlay, ViewableData $inheritedScope = null)
An internal utility function to set up variables in preparation for including a compiled template, then do the include
Effectively this is the common code that both SSViewer#process and SSViewer_FromString#process call
DBHTMLText
process(ViewableData $item, array|null $arguments = null, ViewableData $inheritedScope = null)
Overloaded to track all templates used in the current request
{@inheritDoc}
protected array|null
getSubtemplateFor(string $subtemplate)
Get the appropriate template to use for the named sub-template, or null if none are appropriate
static string
execute_template(string $template, mixed $data, array $arguments = null, object $scope = null, bool $globalRequirements = false)
Execute the given template, passing it the given data.
Used by the <% include %> template tag to process templates.
static string
execute_string(string $content, mixed $data, array $arguments = null, bool $globalRequirements = false)
Execute the evaluated string, passing it the given data.
Used by partial caching to evaluate custom cache keys expressed using template expressions
string
parseTemplateContent(string $content, string $template = "")
Parse given template contents
array
templates()
Returns the filenames of the template that will be rendered. It is a map that may contain 'Content' & 'Layout', and will have to contain 'main'
setTemplateFile(string $type, string $file)
No description
static string
get_base_tag(string $contentGeneratedSoFar)
Return an appropriate base tag for the given template.
It will be closed on an XHTML document, and unclosed on an HTML document.
string
getCacheFile(string $template = null)
Get the cache file for a given template
Useful to get to path to a slow template for example
static array
getTemplatesUsed()
Get the templates used in the current request and the number of times they were called
static void
resetTemplatesUsed()
Reset the array
static protected
trackTemplateUsed(string $templateName)
Helps tracking the use of templates
static protected string
normalizeTemplateName(string $templateName)
Remove base path from template