SSViewer
class SSViewer (View source)
Class that manages themes and interacts with TemplateEngine classes to render templates.
Ensures rendered templates are normalised, e.g have appropriate resources from the Requirements API.
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 | array | A list (highest priority first) of themes to use Only used when $theme_enabled is set to TRUE. |
|
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. |
|
source_file_comments | bool | If true, rendered templates will include comments indicating which template file was used. |
|
rewrite_hash_links | bool | Set if hash links should be rewritten |
Properties
protected static | array | $current_themes | Overridden value of $themes config |
|
protected static | null|bool|string | $current_rewrite_hash_links | Overridden value of rewrite_hash_links config |
|
protected | null|bool|string | $rewriteHashlinks | Instance variable to disable rewrite_hash_links (overrides global default) Leave null to use global state. |
|
protected | bool | $includeRequirements | Determines whether resources from the Requirements API are included in a processed result. |
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.
No description
Traverses the given the given class context looking for candidate template names which match each item in the class hierarchy.
Get an associative array of names to information about callable template provider methods.
Get the template engine used to render templates for this viewer
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
Call this to disable rewriting of links. This is useful in Ajax applications.
The process() method handles the "meat" of the template processing.
Return an appropriate base tag for the given template.
Details
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
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, TemplateEngine|null $templateEngine = null)
No description
static void
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 array
get_templates_by_class(string|object $classOrObject, string $suffix = '', string|null $baseClass = null)
Traverses the given the given class context looking for candidate template names which match each item in the class hierarchy.
This method does NOT check the filesystem, so the resulting list of template candidates may or may not exist - but you can pass these template candidates into the SSViewer constructor or into a TemplateEngine.
If you really need know if a template file exists, you can call hasTemplate() on a TemplateEngine.
static array
getMethodsFromProvider(string $providerInterface, $methodName, bool $createObject = false)
Get an associative array of names to information about callable template provider methods.
TemplateEngine
getTemplateEngine()
Get the template engine used to render templates for this viewer
null|bool|string
getRewriteHashLinks()
Check if rewrite hash links are enabled on this instance
SSViewer
setRewriteHashLinks(null|bool|string $rewrite)
Set if hash links are rewritten for this instance
static null|bool|string
getRewriteHashLinksDefault()
Get default value for rewrite hash links for all modules
static
setRewriteHashLinksDefault(null|bool|string $rewrite)
Set default rewrite hash links
SSViewer
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();
DBHTMLText
process(mixed $item, array $overlay = [])
The process() method handles the "meat" of the template processing.
It takes care of caching the output (via Cache), as well as replacing the special "$Content" and "$Layout" placeholders with their respective subtemplates.
The method injects extra HTML in the header via Requirements::includeInHTML().
Note: You can call this method indirectly by ModelData->renderWith().
static string
getBaseTag(bool $isXhtml = false)
Return an appropriate base tag for the given template.
It will be closed on an XHTML document, and unclosed on an HTML document.
protected SSViewer
setTemplateEngine(TemplateEngine $engine)
Get the engine used to render templates for this viewer.
Note that this is intentionally not public to avoid the engine being set after instantiation.