PHP Class Contao\Template

The class supports loading template files, adding variables to them and then printing them to the screen. It functions as abstract parent class for the two core classes "BackendTemplate" and "FrontendTemplate". Usage: $template = new BackendTemplate(); $template->name = 'Leo Feyer'; $template->output();
Inheritance: extends Controller, use trait TemplateInheritance
Mostra file Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrData array Template data
$strBuffer string Output buffer
$strContentType string Content type
$validJavaScriptTypes array Valid JavaScipt types

Public Methods

Method Description
__call ( string $strKey, array $arrParams ) : mixed Execute a callable and return the result
__construct ( string $strTemplate = '', string $strContentType = 'text/html' ) Create a new template object
__get ( string $strKey ) : mixed Return an object property
__isset ( string $strKey ) : boolean Check whether a property is set
__set ( string $strKey, mixed $varValue ) Set an object property
dumpTemplateVars ( ) Print all template variables to the screen using var_dump
flushAllData ( ) Flush the output buffers
generateFeedTag ( string $href, string $format, string $title ) : string Generate the markup for an RSS feed tag
generateInlineScript ( string $script ) : string Generate the markup for an inline JavaScript
generateInlineStyle ( string $script ) : string Generate the markup for inline CSS code
generateScriptTag ( string $src, boolean $async = false ) : string Generate the markup for a JavaScript tag
generateStyleTag ( string $href, string $media = null ) : string Generate the markup for a style sheet tag
getData ( ) : array Return the template data as array
getFormat ( ) : string Return the output format
getName ( ) : string Return the template name
getResponse ( ) : Response Return a response object
minifyHtml ( string $strHtml ) : string Minify the HTML markup preserving pre, script, style and textarea tags
output ( ) Parse the template file and print it to the screen
parse ( ) : string Parse the template file and return it as string
route ( string $strName, array $arrParams = [] ) : string Return a route relative to the base URL
setData ( array $arrData ) Set the template data from an array
setFormat ( string $strFormat ) Set the output format
setName ( string $strTemplate ) Set the template name
showTemplateVars ( ) Print all template variables to the screen using print_r

Protected Methods

Method Description
compile ( ) Compile the template
getDebugBar ( ) : string Return the debug bar string

Method Details

__call() public method

Execute a callable and return the result
public __call ( string $strKey, array $arrParams ) : mixed
$strKey string The name of the key
$arrParams array The parameters array
return mixed The callable return value

__construct() public method

Create a new template object
public __construct ( string $strTemplate = '', string $strContentType = 'text/html' )
$strTemplate string The template name
$strContentType string The content type (defaults to "text/html")

__get() public method

Return an object property
public __get ( string $strKey ) : mixed
$strKey string The property name
return mixed The property value

__isset() public method

Check whether a property is set
public __isset ( string $strKey ) : boolean
$strKey string The property name
return boolean True if the property is set

__set() public method

Set an object property
public __set ( string $strKey, mixed $varValue )
$strKey string The property name
$varValue mixed The property value

compile() protected method

Compile the template
protected compile ( )

dumpTemplateVars() public method

Print all template variables to the screen using var_dump
public dumpTemplateVars ( )

flushAllData() public method

Flush the output buffers
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0.
public flushAllData ( )

generateFeedTag() public static method

Generate the markup for an RSS feed tag
public static generateFeedTag ( string $href, string $format, string $title ) : string
$href string The script path
$format string The feed format
$title string The feed title
return string The markup string

generateInlineScript() public static method

Generate the markup for an inline JavaScript
public static generateInlineScript ( string $script ) : string
$script string The JavaScript code
return string The markup string

generateInlineStyle() public static method

Generate the markup for inline CSS code
public static generateInlineStyle ( string $script ) : string
$script string The CSS code
return string The markup string

generateScriptTag() public static method

Generate the markup for a JavaScript tag
public static generateScriptTag ( string $src, boolean $async = false ) : string
$src string The script path
$async boolean True to add the async attribute
return string The markup string

generateStyleTag() public static method

Generate the markup for a style sheet tag
public static generateStyleTag ( string $href, string $media = null ) : string
$href string The script path
$media string The media type string
return string The markup string

getData() public method

Return the template data as array
public getData ( ) : array
return array The data array

getDebugBar() protected method

Return the debug bar string
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0.
protected getDebugBar ( ) : string
return string The debug bar markup

getFormat() public method

Return the output format
public getFormat ( ) : string
return string The output format

getName() public method

Return the template name
public getName ( ) : string
return string The template name

getResponse() public method

Return a response object
public getResponse ( ) : Response
return Symfony\Component\HttpFoundation\Response The response object

minifyHtml() public method

Minify the HTML markup preserving pre, script, style and textarea tags
public minifyHtml ( string $strHtml ) : string
$strHtml string The HTML markup
return string The minified HTML markup

output() public method

Parse the template file and print it to the screen
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Template::getResponse() instead.
public output ( )

parse() public method

Parse the template file and return it as string
public parse ( ) : string
return string The template markup

route() public method

Return a route relative to the base URL
public route ( string $strName, array $arrParams = [] ) : string
$strName string The route name
$arrParams array The route parameters
return string The route

setData() public method

Set the template data from an array
public setData ( array $arrData )
$arrData array The data array

setFormat() public method

Set the output format
public setFormat ( string $strFormat )
$strFormat string The output format

setName() public method

Set the template name
public setName ( string $strTemplate )
$strTemplate string The template name

showTemplateVars() public method

Print all template variables to the screen using print_r
public showTemplateVars ( )

Property Details

$arrData protected_oe property

Template data
protected array $arrData
return array

$strBuffer protected_oe property

Output buffer
protected string $strBuffer
return string

$strContentType protected_oe property

Content type
protected string $strContentType
return string

$validJavaScriptTypes protected_oe static_oe property

Valid JavaScipt types
See also: http://www.w3.org/TR/html5/scripting-1.html#scriptingLanguages
protected static array $validJavaScriptTypes
return array