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
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Protected Properties

Свойство Type Description
$arrData array Template data
$strBuffer string Output buffer
$strContentType string Content type
$validJavaScriptTypes array Valid JavaScipt types

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode Description
compile ( ) Compile the template
getDebugBar ( ) : string Return the debug bar string

Method Details

__call() public méthode

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
Résultat mixed The callable return value

__construct() public méthode

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 méthode

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

__isset() public méthode

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

__set() public méthode

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

compile() protected méthode

Compile the template
protected compile ( )

dumpTemplateVars() public méthode

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

flushAllData() public méthode

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

generateFeedTag() public static méthode

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
Résultat string The markup string

generateInlineScript() public static méthode

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

generateInlineStyle() public static méthode

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

generateScriptTag() public static méthode

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
Résultat string The markup string

generateStyleTag() public static méthode

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
Résultat string The markup string

getData() public méthode

Return the template data as array
public getData ( ) : array
Résultat array The data array

getDebugBar() protected méthode

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

getFormat() public méthode

Return the output format
public getFormat ( ) : string
Résultat string The output format

getName() public méthode

Return the template name
public getName ( ) : string
Résultat string The template name

getResponse() public méthode

Return a response object
public getResponse ( ) : Response
Résultat Symfony\Component\HttpFoundation\Response The response object

minifyHtml() public méthode

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

output() public méthode

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 méthode

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

route() public méthode

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
Résultat string The route

setData() public méthode

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

setFormat() public méthode

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

setName() public méthode

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

showTemplateVars() public méthode

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

Property Details

$arrData protected_oe property

Template data
protected array $arrData
Résultat array

$strBuffer protected_oe property

Output buffer
protected string $strBuffer
Résultat string

$strContentType protected_oe property

Content type
protected string $strContentType
Résultat 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
Résultat array