class ThemeResourceLoader implements Flushable, TemplateGlobalProvider (View source)

Handles finding templates from a stack of template manifest objects.

Properties

protected string $base

The base path of the application

protected ThemeList[] $sets

List of template "sets" that contain a test manifest, and have an alias.

protected CacheInterface $cache

Methods

public static 
inst()

No description

public static 
set_instance(ThemeResourceLoader $instance)

Set instance

public
__construct($base = null)

No description

public
addSet(string $set, ThemeList $manifest)

Add a new theme manifest for a given identifier. E.g. '$default'

public
getSet(string $set)

Get a named theme set

public
string
getPath(string $identifier)

Given a theme identifier, determine the path from the root directory

public
string
findTemplate(string|array $template, array $themes = null) deprecated

Attempts to find possible candidate templates from a set of template names from modules, current theme directory and finally the application folder.

public
string
findThemedCSS(string $name, array $themes = null)

Resolve themed CSS path

public
string
findThemedJavascript(string $name, array $themes = null)

Resolve themed javascript path

public
string
findThemedResource(string $resource, array $themes = null)

Resolve a themed resource or directory

public static 
string|null
themedResourceURL(string $resource)

Return the URL for a given themed resource or directory within the project.

public static 
array
get_template_global_variables()

Called by SSViewer to get a list of global variables to expose to the template, the static method to call on this class to get the value for those variables, and the class to use for casting the returned value for use in a template

public
array
getThemePaths(array $themes = null)

Resolve all themes to the list of root folders relative to site root

public static 
flush()

Flush any cached data

public
CacheInterface
getCache()

No description

public
setCache(CacheInterface $cache)

No description

Details

static ThemeResourceLoader inst()

No description

Return Value

ThemeResourceLoader

static set_instance(ThemeResourceLoader $instance)

Set instance

Parameters

ThemeResourceLoader $instance

__construct($base = null)

No description

Parameters

$base

addSet(string $set, ThemeList $manifest)

Add a new theme manifest for a given identifier. E.g. '$default'

Parameters

string $set
ThemeList $manifest

ThemeList getSet(string $set)

Get a named theme set

Parameters

string $set

Return Value

ThemeList

string getPath(string $identifier)

Given a theme identifier, determine the path from the root directory

The mapping from $identifier to path follows these rules:

  • A simple theme name ('mytheme') which maps to the standard themes dir (/themes/mytheme)
  • A theme path with a leading slash ('/mymodule/themes/mytheme') which maps directly to that path.
  • or a vendored theme path. (vendor/mymodule:mytheme) which maps to the nested 'theme' within that module. ('/mymodule/themes/mytheme').
  • A vendored module with no nested theme (vendor/mymodule) which maps to the root directory of that module. ('/mymodule').

Parameters

string $identifier

Theme identifier.

Return Value

string

Path from root, not including leading or trailing forward slash. E.g. themes/mytheme

string findTemplate(string|array $template, array $themes = null) deprecated

deprecated 5.4.0 Will be removed without equivalent functionality to replace it.

Attempts to find possible candidate templates from a set of template names from modules, current theme directory and finally the application folder.

The template names can be passed in as plain strings, or be in the format "type/name", where type is the type of template to search for (e.g. Includes, Layout).

The results of this method will be cached for future use.

Parameters

string|array $template

Template name, or template spec in array format with the keys 'type' (type string) and 'templates' (template hierarchy in order of precedence). If 'templates' is omitted then any other item in the array will be treated as the template list, or list of templates each in the array spec given. Templates with an .ss extension will be treated as file paths, and will bypass theme-coupled resolution.

array $themes

List of themes to use to resolve themes. Defaults to {\SilverStripe\View\SSViewer::get_themes()}

Return Value

string

Absolute path to resolved template file, or null if not resolved. File location will be in the format themes//templates///.ss Note that type (e.g. 'Layout') is not the root level directory under 'templates'.

string findThemedCSS(string $name, array $themes = null)

Resolve themed CSS path

Parameters

string $name

Name of CSS file without extension

array $themes

List of themes, Defaults to {\SilverStripe\View\SSViewer::get_themes()}

Return Value

string

Path to resolved CSS file (relative to base dir)

string findThemedJavascript(string $name, array $themes = null)

Resolve themed javascript path

A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for, and it that doesn't exist and the module parameter is set then a javascript file with that name in the module is used.

Parameters

string $name

The name of the file - eg '/js/File.js' would have the name 'File'

array $themes

List of themes, Defaults to {\SilverStripe\View\SSViewer::get_themes()}

Return Value

string

Path to resolved javascript file (relative to base dir)

string findThemedResource(string $resource, array $themes = null)

Resolve a themed resource or directory

A themed resource can be any file that resides in a theme folder.

Parameters

string $resource

A file path relative to the root folder of a theme

array $themes

An order listed of themes to search, Defaults to {\SilverStripe\View\SSViewer::get_themes()}

Return Value

string

static string|null themedResourceURL(string $resource)

Return the URL for a given themed resource or directory within the project.

A themed resource can be any file that resides in a theme folder.

Parameters

string $resource

Return Value

string|null

static array get_template_global_variables()

Called by SSViewer to get a list of global variables to expose to the template, the static method to call on this class to get the value for those variables, and the class to use for casting the returned value for use in a template

If the method to call is not included for a particular template variable, a method named the same as the template variable will be called

If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used

The first letter of the template variable is case-insensitive. However the method name is always case sensitive.

Return Value

array

Returns an array of items. Each key => value pair is one of three forms:

  • template name (no key)
  • template name => method name
  • template name => [], where the array can contain these key => value pairs
    • "method" => method name
    • "casting" => casting class to use (i.e., Varchar, HTMLFragment, etc)

array getThemePaths(array $themes = null)

Resolve all themes to the list of root folders relative to site root

Parameters

array $themes

List of themes to resolve. Supports named theme sets. Defaults to {\SilverStripe\View\SSViewer::get_themes()}.

Return Value

array

List of root-relative folders in order of precedence.

static flush()

Flush any cached data

CacheInterface getCache()

No description

Return Value

CacheInterface

ThemeResourceLoader setCache(CacheInterface $cache)

No description

Parameters

CacheInterface $cache

Return Value

ThemeResourceLoader