class ThemeResourceLoader implements Flushable (View source)

Handles finding templates from a stack of template manifest objects.

Methods

inst()

No description

static 
set_instance(ThemeResourceLoader $instance)

Set instance

__construct($base = null)

No description

addSet(string $set, ThemeList $manifest)

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

getSet(string $set)

Get a named theme set

string
getPath(string $identifier)

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

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

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

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

Resolve themed CSS path

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

Resolve themed javascript path

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

Resolve a themed resource

array
getThemePaths(array $themes = null)

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

static 
flush()

Flush any cached data

CacheInterface
getCache()

No description

setCache(CacheInterface $cache)

No description

Details

static set_instance(ThemeResourceLoader $instance)

Set instance

Parameters

ThemeResourceLoader $instance

__construct($base = null)

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)

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 ommitted 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 {see \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 {see \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 {see \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

A themed resource and 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 {see \SilverStripe\View\SSViewer::get_themes()}

Return Value

string

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 {see \SilverStripe\View\SSViewer::get_themes()}.

Return Value

array

List of root-relative folders in order of precendence.

static flush()

Flush any cached data

CacheInterface getCache()

Return Value

CacheInterface

ThemeResourceLoader setCache(CacheInterface $cache)

Parameters

CacheInterface $cache

Return Value

ThemeResourceLoader