Class \Prado\Web\UI\TTemplate
A TTemplate object represents a parsed PRADO control template. It can instantiate the template as child controls of a specified control. The template format is like HTML, with the following special tags introduced,
- component tags: a component tag represents the configuration of a component. The tag name is in the format of com:ComponentType, where ComponentType is the component class name. Component tags must be well-formed. Attributes of the component tag are treated as either property initial values, event handler attachment, or regular tag attributes.
- property tags: property tags are used to set large block of attribute values. The property tag name is in the format of prop:AttributeName where AttributeName can be a property name, an event name or a regular tag attribute name.
- group subproperty tags: subproperties of a common property can be configured using <prop:MainProperty SubProperty1="Value1" SubProperty2="Value2" .../>
- directive: directive specifies the property values for the template owner. It is in the format of <%@ property name-value pairs %>;
- expressions: They are in the format of <%= PHP expression %> and <%% PHP statements %>
- comments: There are two kinds of comments, regular HTML comments and special template comments. The former is in the format of , which will be treated as text strings. The latter is in the format of <!-- comments --!>, which will be stripped out.
Tags other than the above are not required to be well-formed.
A TTemplate object represents a parsed PRADO template. To instantiate the template for a particular control, call instantiateIn($control), which will create and intialize all components specified in the template and set their parent as $control.
Class hierarchy
Author: Qiang Xue <qiang.xue@gmail.com>Since: 3.0
public
|
__construct(string $template, string $contextPath[, null|string $tplFile = null ][, int $startingLine = 0 ][, bool $sourceTemplate = true ]) : mixed
Constructor.
The template will be parsed after construction. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getIncludedFiles() : array<string|int, mixed>
TTemplateManager calls this method for caching the included file modification times.
|
public
|
|
public
|
|
public
|
|
public
|
instantiateIn(TControl $tplControl[, null|TControl $parentControl = null ]) : mixed
Instantiates the template.
Content in the template will be instantiated as components and text strings and passed to the specified parent control. |
public
|
|
protected
|
configureComponent(TComponent $component, string $name, mixed $value) : mixed
Configures a property of a non-control component.
|
protected
|
configureControl(TControl $control, string $name, mixed $value) : mixed
Configures a property/event of a control.
|
protected
|
configureEvent(TControl $control, string $name, string $value, TControl $contextControl) : mixed
Configures an event for a control.
|
protected
|
configureProperty(TControl $component, string $name, mixed $value) : mixed
Configures a simple property for a component.
|
protected
|
configureSubProperty(TControl $component, string $name, mixed $value) : mixed
Configures a subproperty for a component.
|
protected
|
handleException(Exception $e, int $line[, null|string $input = null ]) : mixed
Handles template parsing exception.
This method rethrows the exception caught during template parsing. It adjusts the error location by giving out correct error line number and source file. |
protected
|
isClassBehaviorMethod(ReflectionClass $class, string $method) : bool
Checks if the given method belongs to a previously attached class behavior.
|
protected
|
parse(string $input) : mixed
Parses a template string.
This template parser recognizes five types of data: regular string, well-formed component tags, well-formed property tags, directives, and expressions. The parsing result is returned as an array. Each array element can be of three types:
Note, attribute names are treated as case-insensitive and will be turned into lower cases. Component and directive types are case-sensitive. Container index is the index to the array element that stores the container object. If an object has no container, its container index is -1. |
protected
|
|
protected
|
parseAttributes(string $str, mixed $offset) : array<string|int, mixed>
Parses the attributes of a tag from a string.
|
protected
|
|
protected
|
|
protected
|
public
mixed
|
CONFIG_ASSET
|
2
|
public
mixed
|
CONFIG_DATABIND
Different configurations of component property/event/attribute
|
0
|
public
mixed
|
CONFIG_EXPRESSION
|
1
|
public
mixed
|
CONFIG_LOCALIZATION
|
4
|
public
mixed
|
CONFIG_PARAMETER
|
3
|
public
mixed
|
CONFIG_TEMPLATE
|
5
|
public
mixed
|
REGEX_RULES
'<!--.*?--!>' - template comments
'<!--.*?-->' - HTML comments
'<\/?com:([\w\.\\\]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>' - component tags
'<\/?prop:([\w\.\-]+)\s*>' - property tags
'<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>' - directives
'<%[%#~\/\\$=\\[](.*?)%>' - expressions
'<prop:([\w\.\-]+)((?:\s*[\w\.\-]+=\'.*?\'|\s*[\w\.\-]+=".*?"|\s*[\w\.\-]+=<%.*?%>)*)\s*\/>' - group subproperty tags
|
'/<!--.*?--!>|<!---.*?--->|<\\/?com:([\\w\\.\\\\]+)((?:\\s*[\\w\\.]+\\s*=\\s*\'.*?\'|\\s*[\\w\\.]+\\s*=\\s*".*?"|\\s*[\\w\\.]+\\s*=\\s*<%.*?%>)*)\\s*\\/?>|<\\/?prop:([\\w\\.\\-]+)\\s*>|<%@\\s*((?:\\s*[\\w\\.]+\\s*=\\s*\'.*?\'|\\s*[\\w\\.]+\\s*=\\s*".*?")*)\\s*%>|<%[%#~\\/\\$=\\[](.*?)%>|<prop:([\\w\\.\\-]+)((?:\\s*[\\w\\.\\-]+\\s*=\\s*\'.*?\'|\\s*[\\w\\.\\-]+\\s*=\\s*".*?"|\\s*[\\w\\.\\-]+\\s*=\\s*<%.*?%>)*)\\s*\\/>/msS'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |