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.

Properties

protected static array $current_themes

Overridden value of $themes config

null|bool|string $current_rewrite_hash_links

Overridden value of rewrite_hash_links config

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

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(string|array $templates, TemplateEngine|null $templateEngine = null)

No description

public static 
void
set_themes(array $themes)

Assign the list of active themes to apply.

public static 
add_themes(array $themes)

Add to the list of active themes to apply

public static 
array
get_themes()

Get the list of active themes

public 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.

public static 
array
getMethodsFromProvider(string $providerInterface, $methodName, bool $createObject = false)

Get an associative array of names to information about callable template provider methods.

public
getTemplateEngine()

Get the template engine used to render templates for this viewer

public
null|bool|string
getRewriteHashLinks()

Check if rewrite hash links are enabled on this instance

public
setRewriteHashLinks(null|bool|string $rewrite)

Set if hash links are rewritten for this instance

public static 
null|bool|string
getRewriteHashLinksDefault()

Get default value for rewrite hash links for all modules

public static 
setRewriteHashLinksDefault(null|bool|string $rewrite)

Set default rewrite hash links

public
includeRequirements(bool $incl = true)

Flag whether to include the requirements in this response.

public
process(mixed $item, array $overlay = [])

The process() method handles the "meat" of the template processing.

public static 
string
getBaseTag(bool $isXhtml = false)

Return an appropriate base tag for the given template.

protected
setTemplateEngine(TemplateEngine $engine)

Get the engine used to render templates for this viewer.

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

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();

Parameters

mixed ...$args

Return Value

Injectable

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).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(string|array $templates, TemplateEngine|null $templateEngine = null)

No description

Parameters

string|array $templates

If passed as a string, used as the "main" template. If passed as an array, it can be used for template inheritance (first found template "wins"). Usually the array values are PHP class names, which directly correlate to template names.

array('MySpecificPage', 'MyPage', 'Page')
TemplateEngine|null $templateEngine

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.

Parameters

array $themes

Return Value

void

static add_themes(array $themes)

Add to the list of active themes to apply

Parameters

array $themes

static array get_themes()

Get the list of active themes

Return Value

array

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.

Parameters

string|object $classOrObject

Valid class name, or object

string $suffix
string|null $baseClass

Class to halt ancestry search at

Return Value

array

static array getMethodsFromProvider(string $providerInterface, $methodName, bool $createObject = false)

Get an associative array of names to information about callable template provider methods.

Parameters

string $providerInterface
$methodName
bool $createObject

Return Value

array

TemplateEngine getTemplateEngine()

Get the template engine used to render templates for this viewer

Return Value

TemplateEngine

Check if rewrite hash links are enabled on this instance

Return Value

null|bool|string

Set if hash links are rewritten for this instance

Parameters

null|bool|string $rewrite

Return Value

SSViewer

static null|bool|string getRewriteHashLinksDefault()

Get default value for rewrite hash links for all modules

Return Value

null|bool|string

static setRewriteHashLinksDefault(null|bool|string $rewrite)

Set default rewrite hash links

Parameters

null|bool|string $rewrite

includeRequirements(bool $incl = true)

Flag whether to include the requirements in this response.

Parameters

bool $incl

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().

Parameters

mixed $item
array $overlay

Associative array of fields for use in the template. These will override properties and methods with the same name from $data and from global template providers.

Return Value

DBHTMLText

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.

Parameters

bool $isXhtml

Whether the DOCTYPE is xhtml or not.

Return Value

string

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.

Parameters

TemplateEngine $engine

Return Value

SSViewer