## Class TTemplate

Description

Implements interfaces:

- ITemplate

TTemplate implements PRADO template parsing logic.

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.

- directive: directive specifies the property values for the template owner.

It is in the format of &lt;% property name-value pairs %&gt;

- expressions: They are in the formate of &lt;= PHP expression &gt; and &lt;% PHP statements &gt;
- comments: There are two kinds of comments, regular HTML comments and special template comments.

The former is in the format of &lt;!-- comments --&gt;, which will be treated as text strings. The latter is in the format of &lt;%* comments %&gt;, 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.

- since: 3.0
- version: $Revision: $ $Date: $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/UI/TTemplateManager.php (line 146)

    TComponent
       |
       --TApplicationComponent
          |
          --TTemplate

Class Constant Summary
CONFIG_ASSET = 2
CONFIG_DATABIND = 0
CONFIG_EXPRESSION = 1
CONFIG_LOCALIZATION = 4
CONFIG_PARAMETER = 3
CONFIG_TEMPLATE = 5
REGEX_RULES = '/<!--.*?--!>|<!--.*?-->|<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>|<%[%#~\\$=\\[](.*?)%>/msS'
Method Summary
void configureComponent (TComponent $component, string $name, mixed $value)
void configureControl (TControl $control, string $name, mixed $value)
void configureEvent (TControl $component, string $name, string $value)
void configureProperty (TComponent $component, string $name, mixed $value)
void configureSubProperty (TComponent $component, string $name, mixed $value)
TTemplate __construct (string $template, string $contextPath, [string $tplFile = null], integer $startingLine, [boolean $sourceTemplate = true])
string getContextPath ()
array getDirective ()
boolean getIsSourceTemplate ()
array &getItems ()
void instantiateIn (TControl $tplControl)
void parse (string $input)
array parseAttribute (string $value)
array parseAttributes (string $str, mixed $offset)
void parseTemplateProperty (mixed $content, mixed $offset)
void validateAttributes (mixed $type, mixed $attributes)
Methods
configureComponent (line 350)

Configures a property of a non-control component.

- access: protected

void configureComponent (TComponent $component, string $name, mixed $value)

- TComponent $component: component to be configured
- string $name: property name
- mixed $value: property initial value

configureControl (line 334)

Configures a property/event of a control.

- access: protected

void configureControl (TControl $control, string $name, mixed $value)

- TControl $control: control to be configured
- string $name: property name
- mixed $value: property initial value

configureEvent (line 364)

Configures an event for a control.

- access: protected

void configureEvent (TControl $component, string $name, string $value)

- TControl $component: control to be configured
- string $name: event name
- string $value: event handler

configureProperty (line 378)

Configures a simple property for a component.

- access: protected

void configureProperty (TComponent $component, string $name, mixed $value)

- TComponent $component: component to be configured
- string $name: property name
- mixed $value: property initial value

configureSubProperty (line 430)

Configures a subproperty for a component.

- access: protected

void configureSubProperty (TComponent $component, string $name, mixed $value)

- TComponent $component: component to be configured
- string $name: subproperty name
- mixed $value: subproperty initial value

Constructor __construct (line 209)

Constructor.

The template will be parsed after construction.

- access: public

TTemplate __construct (string $template, string $contextPath, [string $tplFile = null], integer $startingLine, [boolean $sourceTemplate = true])

- string $template: the template string
- string $contextPath: the template context directory
- string $tplFile: the template file, null if no file
- integer $startingLine: the line number that parsing starts from (internal use)
- boolean $sourceTemplate: whether this template is a source template, i.e., this template is loaded from some external storage rather than from within another template.

getContextPath (line 232)

- return: context directory path
- access: public

string getContextPath ()
getDirective (line 240)

- return: name-value pairs declared in the directive
- access: public

array getDirective ()
getIsSourceTemplate (line 224)

- return: whether this template is a source template, i.e., this template is loaded from some external storage rather than from within another template.
- access: public

boolean getIsSourceTemplate ()
getItems (line 248)

- return: the parsed template
- access: public

array &getItems ()
instantiateIn (line 259)

Instantiates the template.

Content in the template will be instantiated as components and text strings and passed to the specified parent control.

- access: public

void instantiateIn (TControl $tplControl)

- TControl $tplControl: the parent control

parse (line 487)

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:

- a string, 0: container index; 1: string content;
- a component tag, 0: container index; 1: component type; 2: attributes (name=>value pairs)

If a directive is found in the template, it will be parsed and can be retrieved via getDirective, which returns an array consisting of name-value pairs in the directive.

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.

- access: protected
- throws: TConfigurationException if a parsing error is encountered

void parse (string $input)

- string $input: the template string

parseAttribute (line 745)

Parses a single attribute.

- return: attribute initialization
- access: protected

array parseAttribute (string $value)

- string $value: the string to be parsed.

parseAttributes (line 702)

Parses the attributes of a tag from a string.

- return: attribute values indexed by names.
- access: protected

array parseAttributes (string $str, mixed $offset)

- string $str: the string to be parsed.

parseTemplateProperty (line 734)

- access: protected

void parseTemplateProperty (mixed $content, mixed $offset)
validateAttributes (line 764)

- access: protected

void validateAttributes (mixed $type, mixed $attributes)

#### Inherited Methods

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

Inherited From TComponent

> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Class Constants
CONFIG_ASSET = 2 (line 163)
CONFIG_DATABIND = 0 (line 161)

Different configurations of component property/event/attribute

CONFIG_EXPRESSION = 1 (line 162)
CONFIG_LOCALIZATION = 4 (line 165)
CONFIG_PARAMETER = 3 (line 164)
CONFIG_TEMPLATE = 5 (line 166)
REGEX_RULES = '/<!--.*?--!>|<!--.*?-->|<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>|<%[%#~\\$=\\[](.*?)%>/msS' (line 156)

'<!--.*?--!>' - template comments

'<!--.*?-->' - HTML comments '<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>' - component tags '<\/?prop:([\w\.]+)\s*>' - property tags '<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>' - directives '<%[%#~\\$=\\[](.*?)%>' - expressions

Documentation generated on Mon, 01 May 2006 23:04:52 -0400 by phpDocumentor 1.3.0RC4