Base template rendering class.

Note that due to a lack of late static binding support, all static properties and any method that deals with those properties (via "self", regardless of whether it's static or not) must be (re)defined in child classes!

package XenForo_Core

 Methods

Constructor

__construct(string $templateName, array $params) 

Parameters

$templateName

string

Template name

$params

array

Key-value parameters

Implicit string cast renders the template.

__toString() : string

Returns

string

Adds required external for this type of template to be output later.

addRequiredExternal(string $type, string $requirement) 

Parameters

$type

string

Type of requirement

$requirement

string

Value for requirement

Calls the specified template hook event.

callTemplateHook(string $name, string $contents, array $params) : string

Params passed by template explicitly will respect mappings and greater context. Raw params are still available via the template object.

Parameters

$name

string

Name of the hook

$contents

string

Contents of the hook; may be empty

$params

array

List of params to pass specifically; these will respect mappings.

Returns

stringNew version of the contents (could be modified)

Creates a new template object of the current type.

create(string $templateName, array $params) : \XenForo_Template_Abstract

Mainly helpful if an event only has the current template object in scope.

Parameters

$templateName

string

$params

array

Returns

Get a single template parameter.

getParam($key) : mixed

Parameters

$key

string

Returns

mixedNull if not found.

Get all template parameters.

getParams() : array

Returns

array

Gets the required CSS as an HTML tag.

getRequiredCssAsHtml(string $requirement) : string

Expected arg is simple a URL.

Parameters

$requirement

string

Returns

string

Gets the URL to fetch the list of required CSS templates.

getRequiredCssUrl(array $requirements) : string

Requirements should be a list of CSS templates, not including the trailing ".css".

Parameters

$requirements

array

Returns

string

Gets required externals in a structured way.

getRequiredExternals(string $type) : array

Values will be returned as a list of URLs.

Parameters

$type

string

Returns

arrayList of URLs

Gets required external resources as HTML for use in a template directly.

getRequiredExternalsAsHtml(string $type) : string

Parameters

$type

string

Type of requirement to fetch

Returns

stringRequirements as HTML

getRequiredExternalsAsJson()

getRequiredExternalsAsJson() 

Gets the list of required JavaScript files as HTML script tags.

getRequiredJavaScriptAsHtml(array $requirements) : string

Parameters

$requirements

array

Array of paths to JS files.

Returns

string

getTemplateName()

getTemplateName() : string

Returns

string

Helper function get the list of templates that are waiting to be loaded.

getToLoadList() : array

Returns

array

Error handler that traps errors in templates.

handleTemplateError(integer $errorType, string $errorString, string $file, integer $line) 

Parameters

$errorType

integer

Type of error (one of the E_* constants)

$errorString

string

$file

string

$line

integer

Specify a template that needs to be preloaded for use later.

preloadTemplate(string $templateName) 

This is useful if you think a render is going to be called before the template you require is to be used.

Parameters

$templateName

string

Template to preload

Renders the specified template and returns the output.

render() : string

Returns

string

Resets the template system state.

reset() 

Sets the language ID that templates will be retrieved from.

setLanguageId(integer $languageId) 

Parameters

$languageId

integer

Add a single param to the template.

setParam($key, $value) 

Overwrites parameters with the same name.

Parameters

$key

string

$value

Add an array of params to the template.

setParams(array $params) 

Overwrites parameters with the same name.

Parameters

$params

array

Manually sets a template.

setTemplate(string $templateName, string $templateValue) 

This is primarily useful for testing.

Parameters

$templateName

string

Name of the template

$templateValue

string

Value for the template

Gets the list of required external resources.

_getRequiredExternals() : array

Returns

array

Goes to the data source to load the list of templates.

_getTemplatesFromDataSource(array $templateList) : array

Parameters

$templateList

array

Template list

Returns

arrayKey-value pairs of template titles/compiled templates

Load the named template.

_loadTemplate(string $templateName) : string

Parameters

$templateName

string

Template name

Returns

stringCompiled version of the template

Loads the file path where a template is located in the file system, if templates are being stored in the file system.

_loadTemplateFilePath(string $templateName) 

Parameters

$templateName

string

Template name

Loads a template out of the local template cache.

_loadTemplateFromCache(string $templateName) : string

If the template does not exist, it will be set to an empty string. This will be overwritten if the template is loaded from the data source.

Parameters

$templateName

string

Template name

Returns

stringCompiled template

Bulk load all templates that are required.

_loadTemplates() 

Merges in extra container data from the template render.

_mergeExtraContainerData(array $extraData) 

Parameters

$extraData

array

Merges key-value pairs of template names/compiled templates into the local template cache.

_mergeIntoTemplateCache(array $templates) 

Parameters

$templates

array

Templates (key: name, value: compiled output)

Non-static method for pre-loading a template.

_preloadTemplate(string $templateName) 

Parameters

$templateName

string

Template name

_processJsUrls()

_processJsUrls(array $jsFiles) 

Parameters

$jsFiles

Internal template rendering.

_renderInternal(string $__template, array $__extraData) : string

Parameters

$__template

string

Template text or name of template file

$__extraData

array

Returned extra data from the render

Returns

stringRendered template

Resets the to load list to empty.

_resetToLoadList() 

Sets the list of required external resources.

_setRequiredExternals(array $required) 

Parameters

$required

array

Determines whether we are using templates in the file system.

_usingTemplateFiles() : boolean

Returns

boolean

 Properties

 

Base path to compiled templates that are stored on disk.

$_filePath : string

All child classes must redefine this property!

 

The ID of the language that templates will be retrieved from.

$_languageId : integer

 

Key-value params to make available in the template.

$_params : array

 

Array of required external resources for this type of template.

$_required : array

All child classes must redefine this property!

 

Cached template data.

$_templateCache : array

Key is the template name; value is the compiled template. All child classes must redefine this property!

 

PHP errors generated during template evaluation.

$_templateErrors : array

 

Name of the template to load.

$_templateName : string

 

A list of templates that still need to be loaded.

$_toLoad : array

Key is the template name. All child classes must redefine this property!