PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class 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 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.

TComponent
Extended by TApplicationComponent
Extended by TTemplate implements ITemplate
Package: System\Web\UI
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/UI/TTemplateManager.php
Methods summary
public
# __construct( string $template, string $contextPath, string $tplFile = null, integer $startingLine = 0, boolean $sourceTemplate = true )

Constructor. The template will be parsed after construction.

Constructor. The template will be parsed after construction.

Parameters

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

Overrides

TComponent::__construct()
public string
# getTemplateFile( )

Returns

string
template file path if available, null otherwise.
public boolean
# getIsSourceTemplate( )

Returns

boolean
whether this template is a source template, i.e., this template is loaded from some external storage rather than from within another template.
public string
# getContextPath( )

Returns

string
context directory path
public array
# getDirective( )

Returns

array
name-value pairs declared in the directive
public string
# getHashCode( )

Returns

string
hash code that can be used to identify the template
public array &
# getItems( )

Returns

array
the parsed template
public
# instantiateIn( TControl $tplControl, TControl $parentControl = null )

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

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

Parameters

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

Implementation of

ITemplate::instantiateIn()
protected
# configureControl( TControl $control, string $name, mixed $value )

Configures a property/event of a control.

Configures a property/event of a control.

Parameters

$control
TControl
control to be configured
$name
string
property name
$value
mixed
property initial value
protected
# configureComponent( TComponent $component, string $name, mixed $value )

Configures a property of a non-control component.

Configures a property of a non-control component.

Parameters

$component
TComponent
component to be configured
$name
string
property name
$value
mixed
property initial value
protected
# configureEvent( TControl $control, string $name, string $value, TControl $contextControl )

Configures an event for a control.

Configures an event for a control.

Parameters

$control
TControl
control to be configured
$name
string
event name
$value
string
event handler
$contextControl
TControl
context control
protected
# configureProperty( TComponent $component, string $name, mixed $value )

Configures a simple property for a component.

Configures a simple property for a component.

Parameters

$component
TComponent
component to be configured
$name
string
property name
$value
mixed
property initial value
protected
# configureSubProperty( TComponent $component, string $name, mixed $value )

Configures a subproperty for a component.

Configures a subproperty for a component.

Parameters

$component
TComponent
component to be configured
$name
string
subproperty name
$value
mixed
subproperty initial value
protected
# parse( string $input )

Parses a template string.

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 TTemplate::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.

Parameters

$input
string
the template string

Throws

TConfigurationException
if a parsing error is encountered
protected array
# parseAttributes( string $str, mixed $offset )

Parses the attributes of a tag from a string.

Parses the attributes of a tag from a string.

Parameters

$str
string
the string to be parsed.
$offset

Returns

array
attribute values indexed by names.
protected
# parseTemplateProperty( mixed $content, mixed $offset )
protected array
# parseAttribute( string $value )

Parses a single attribute.

Parses a single attribute.

Parameters

$value
string
the string to be parsed.

Returns

array
attribute initialization
protected
# validateAttributes( mixed $type, mixed $attributes )
public array
# getIncludedFiles( )

Returns

array
list of included external template files
protected
# handleException( Exception $e, integer $line, string $input = null )

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.

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.

Parameters

$e
Exception
template exception
$line
integer
line number
$input
string
template string if no source file is used
protected string
# preprocess( string $input )

Preprocesses the template string by including external templates

Preprocesses the template string by including external templates

Parameters

$input
string
template string

Returns

string
expanded template string
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string REGEX_RULES '/<!--.*?--!>|<!---.*?--->|<\/?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'
#

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

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

integer CONFIG_DATABIND 0
#

Different configurations of component property/event/attribute

Different configurations of component property/event/attribute

integer CONFIG_EXPRESSION 1
#
integer CONFIG_ASSET 2
#
integer CONFIG_PARAMETER 3
#
integer CONFIG_LOCALIZATION 4
#
integer CONFIG_TEMPLATE 5
#
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO