PHP Class Contao\TemplateLoader

The class stores template names and automatically loads the files upon their first usage. It uses a mapper array to support complex nesting and arbitrary subfolders to store the template files in. Usage: ClassLoader::addFile('moo_mediabox', 'core/templates');
Show file Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$files array Known files

Public Methods

Method Description
addFile ( string $name, string $file ) Add a new template with its file path
addFiles ( array $files ) Add multiple new templates with their file paths
getDefaultPath ( string $template, string $format ) : string Return the path to the default template
getFiles ( ) : array Return the template files as array
getPath ( string $template, string $format, string $custom = 'templates' ) : string Return a template path
getPrefixedFiles ( string $prefix ) : array Return the files matching a prefix as array
initialize ( ) Find the templates in the Contao resource folders.

Method Details

addFile() public static method

Add a new template with its file path
public static addFile ( string $name, string $file )
$name string The template name
$file string The path to the template folder

addFiles() public static method

Add multiple new templates with their file paths
public static addFiles ( array $files )
$files array An array of files

getDefaultPath() public static method

Return the path to the default template
public static getDefaultPath ( string $template, string $format ) : string
$template string The template name
$format string The output format (e.g. "html5")
return string The path to the default template file

getFiles() public static method

Return the template files as array
public static getFiles ( ) : array
return array An array of files

getPath() public static method

Return a template path
public static getPath ( string $template, string $format, string $custom = 'templates' ) : string
$template string The template name
$format string The output format (e.g. "html5")
$custom string The custom templates folder (defaults to "templates")
return string The path to the template file

getPrefixedFiles() public static method

Return the files matching a prefix as array
public static getPrefixedFiles ( string $prefix ) : array
$prefix string The prefix (e.g. "moo_")
return array An array of matching files

initialize() public static method

Find the templates in the Contao resource folders.
public static initialize ( )

Property Details

$files protected static property

Known files
protected static array $files
return array