- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml
Classes:
IBroadcastEventReceiver
IButtonControl
INamingContainer
IPageStatePersister
IPostBackDataHandler
IPostBackEventHandler
ISurroundable
ITemplate
ITheme
IValidatable
IValidator
TBroadcastEventParameter
TCachePageStatePersister
TClientScriptManager
TClientSideOptions
TCommandEventParameter
TCompositeControl
TCompositeLiteral
TControl
TControlAdapter
TControlCollection
TEmptyControlCollection
TForm
THead
THtmlWriter
TPage
TPageStateFormatter
TPageStatePersister
TSessionPageStatePersister
TTemplate
TTemplateControl
TTemplateManager
TTextProcessor
TTheme
TThemeManager

Keyword

# Class TTemplate

    TComponent
       |
       --TApplicationComponent
          |
          --TTemplate

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.

- 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 formate 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 <!-- comments -->, 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.

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Constructor Summary
public | __construct Array Constructor.

Method Summary
protected void | configureComponent ( TComponent $component, string $name, mixed $value) Configures a property of a non-control component.
protected void | configureControl ( TControl $control, string $name, mixed $value) Configures a property/event of a control.
protected void | configureEvent ( TControl $control, string $name, string $value, TControl $contextControl) Configures an event for a control.
protected void | configureProperty ( TComponent $component, string $name, mixed $value) Configures a simple property for a component.
protected void | configureSubProperty ( TComponent $component, string $name, mixed $value) Configures a subproperty for a component.
string | getContextPath ()
array | getDirective ()
string | getHashCode ()
array | getIncludedFiles ()
boolean | getIsSourceTemplate ()
array | getItems ()
string | getTemplateFile ()
protected void | handleException ( Exception $e, int $line, string $input) Handles template parsing exception.
void | instantiateIn ( TControl $tplControl, TControl $parentControl) Instantiates the template.
protected void | parse ( string $input) Parses a template string.
protected array | parseAttribute ( string $value) Parses a single attribute.
protected array | parseAttributes ( string $str, mixed $offset) Parses the attributes of a tag from a string.
protected void | parseTemplateProperty ( mixed $content, mixed $offset)
protected string | preprocess ( string $input) Preprocesses the template string by including external templates
protected void | validateAttributes ( mixed $type, mixed $attributes)

Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()

Methods Inherited From TComponent

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

Constant Summary
int | CONFIG_ASSET |
int | CONFIG_DATABIND | Different configurations of component property/event/attribute
int | CONFIG_EXPRESSION |
int | CONFIG_LOCALIZATION |
int | CONFIG_PARAMETER |
int | CONFIG_TEMPLATE |

string

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

Constructor Details

## __construct

public __construct | Array

Constructor.

The template will be parsed after construction.

Method Details

## configureComponent

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

Configures a property of a non-control component.

Input
TComponent | $component | component to be configured
string | $name | property name
mixed | $value | property initial value
Output
Exception

## configureControl

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

Configures a property/event of a control.

Input
TControl | $control | control to be configured
string | $name | property name
mixed | $value | property initial value
Output
Exception

## configureEvent

protected void configureEvent | (TControl $control , string $name , string $value , TControl $contextControl )

Configures an event for a control.

Input
TControl | $control | control to be configured
string | $name | event name
string | $value | event handler
TControl | $contextControl | context control
Output
Exception

## configureProperty

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

Configures a simple property for a component.

Input
TComponent | $component | component to be configured
string | $name | property name
mixed | $value | property initial value
Output
Exception

## configureSubProperty

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

Configures a subproperty for a component.

Input
TComponent | $component | component to be configured
string | $name | subproperty name
mixed | $value | subproperty initial value
Output
Exception

## getContextPath

public string getContextPath | ()

Output
string | context directory path
Exception

## getDirective

public array getDirective | ()

Output
array | name-value pairs declared in the directive
Exception

## getHashCode

public string getHashCode | ()

Output
string | hash code that can be used to identify the template
Exception

## getIncludedFiles

public array getIncludedFiles | ()

Output
array | list of included external template files
Exception

## getIsSourceTemplate

public boolean getIsSourceTemplate | ()

Output
boolean | whether this template is a source template, i.e., this template is loaded from some external storage rather than from within another template.
Exception

## getItems

public array getItems | ()

Output
array | the parsed template
Exception

## getTemplateFile

public string getTemplateFile | ()

Output
string | template file path if available, null otherwise.
Exception

## handleException

protected void handleException | (Exception $e , int $line , string $input )

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.

Input
Exception | $e | template exception
int | $line | line number
string | $input | template string if no source file is used
Output
Exception

## instantiateIn

public void instantiateIn | (TControl $tplControl , TControl $parentControl )

Instantiates the template.

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

Input
TControl | $tplControl | the control who owns the template
TControl | $parentControl | the control who will become the root parent of the controls on the template. If null, it uses the template control.
Output
Exception

## parse

protected void parse | (string $input )

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.

Input
string | $input | the template string
Output
Exception
throws | TConfigurationException if a parsing error is encountered

## parseAttribute

protected array parseAttribute | (string $value )

Parses a single attribute.

Input
string | $value | the string to be parsed.
Output
array | attribute initialization
Exception

## parseAttributes

protected array parseAttributes | (string $str , mixed $offset )

Parses the attributes of a tag from a string.

Input
string | $str | the string to be parsed.
mixed | $offset |
Output
array | attribute values indexed by names.
Exception

## parseTemplateProperty

protected void parseTemplateProperty | (mixed $content , mixed $offset )

Input
mixed | $content |
mixed | $offset |
Output
Exception

## preprocess

protected string preprocess | (string $input )

Preprocesses the template string by including external templates

Input
string | $input | template string
Output
string | expanded template string
Exception

## validateAttributes

protected void validateAttributes | (mixed $type , mixed $attributes )

Input
mixed | $type |
mixed | $attributes |
Output
Exception

Constant Details

### CONFIG_ASSET

#### Type:

int

#### Value:

2

### CONFIG_DATABIND

Different configurations of component property/event/attribute

#### Type:

int

#### Value:

0

### CONFIG_EXPRESSION

#### Type:

int

#### Value:

1

### CONFIG_LOCALIZATION

#### Type:

int

#### Value:

4

### CONFIG_PARAMETER

#### Type:

int

#### Value:

3

### CONFIG_TEMPLATE

#### Type:

int

#### Value:

5

### 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

#### Type:

string

#### Value:

'/<!--.*?--!>|<!---.*?--->|<\/?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'