Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Template Class Reference

Manages a rapila Template (*.tmpl) More...

Inheritance diagram for Template:

Public Member Functions

 __construct ($sTemplateName, $mPath=null, $bTemplateIsTextOnly=false, $bDirectOutput=false, $sTargetEncoding=null, $sRootTemplateName=null, $iDefaultFlags=0)
 derivativeTemplate ($sTemplateName, $mPath=false, $bTemplateIsTextOnly=false)
 hasIdentifier ($sName, $sValue=TemplateIdentifier::PARAMETER_EMPTY_VALUE)
 listValuesByIdentifier ($sType)
 replaceAt ($iIndex, $mReplacement=null, $iLength=1)
 identifiersMatching ($sName=null, $sValue=null, $aParameters=null, $bFindFirst=false, $iStartPosition=0)
 findEndIfForIf ($oIf)
 setDefaultFlags ($iDefaultFlags)
 replaceIdentifier ($mIdentifier, $mText, $sValue=TemplateIdentifier::PARAMETER_EMPTY_VALUE, $iFlags=0, $mFunction=null)
 replaceIdentifierMultiple ($mIdentifier, $mText=null, $sValue=TemplateIdentifier::PARAMETER_EMPTY_VALUE, $iFlags=0, $mFunction=null)
 replaceIdentifierMultipleCallback ($sIdentifier, $mCallbackObject, $sCallbackMethod="getTextForReplaceIdentifier", $iFlags)
 replaceIdentifierCallback ($sIdentifier, $mCallbackObject, $sCallbackMethod=null, $iFlags=0)
 replacePstring ($sPstringName, $aParameters, $sStringKey=null)
 render ($bIsForSubtemplate=false)
 doIncludes ()
 getSentOutput ()
 __toString ()
 __clone ()
 __wakeup ()
 closeIdentifier ($sName, $sValue=null)
 getTemplateName ()
 getTemplatePath ()
 getCharset ()

Static Public Member Functions

static htmlEncode ($sString)
static listTemplates ($mDirName=DIRNAME_TEMPLATES, $bListSubdirs=false, $bFlag=null)

Public Attributes

const NO_HTML_ESCAPE = 1
const ESCAPE = 2
const NO_NEWLINE = 32
const NO_NEW_CONTEXT = 64
const NO_RECODE = 256
const STRIP_TAGS = 512
const URL_ENCODE = 2048
 $bKillIdentifiersBeforeRender = true
 If set to false, identifiers will be inserted into the final output.
 $iDefaultFlags = 0
 Default flags are ORed against given flags in all operations. Default flags are also inherited to included templates.

Static Public Attributes

static $SUFFIX = '.tmpl'
 template suffix
static $ANY_VALUE = -1

Detailed Description

Manages a rapila Template (*.tmpl)

The Template class is used to manage building a tree with static template texts and dynamic identifiers that have the form of {{identifier=value;param=value}}. Those can have special meaning (SpecialTemplateIdentifierActions) and be replaced by the Template class or can be replaced by the user of the template using replaceIdentifier() or replaceIdentifierMultiple(). All replaceIdentifier… methods take a flag parameter. The possible flags can be bitwise ORed together. The flags are described in the constants section. You can also provide a new template with some default flags. All Templates whose file name start with “e_mail_” will automatically get the NO_HTML_ESCAPE flag while those ending in .css.tmpl or .js.tmpl will automatically get NO_HTML_ESCAPE|ESCAPE.

Constructor & Destructor Documentation

Template::__construct (   $sTemplateName,
  $mPath = null,
  $bTemplateIsTextOnly = false,
  $bDirectOutput = false,
  $sTargetEncoding = null,
  $sRootTemplateName = null,
  $iDefaultFlags = 0 
string$sTemplateNametemplate name
string | array$mPathtemplate dir path
boolean$bTemplateIsTextOnlytemplate is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
boolean$bDirectOutputtemplate will output directly to stream? only one the main template should have set this to true
string$sTargetEncodingtarget encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
string$sRootTemplateNameroot template name, used internally when including subtemplates, default=null
int$iDefaultFlagsdefault flags, will be ORed to the flags you provide when calling replaceIdentifier() and replaceIdentifierMultiple()

Member Function Documentation

Template::doIncludes ( )

Searches for all not-yet replaced includeTemplate special identifiers (usually only the ones that have position=last on them since all the other ones are already included on template render). This is useful when using a template identifier in the include name.

Template::listValuesByIdentifier (   $sType)
Template::render (   $bIsForSubtemplate = false)
Template::replaceIdentifier (   $mIdentifier,
  $sValue = TemplateIdentifier::PARAMETER_EMPTY_VALUE,
  $iFlags = 0,
  $mFunction = null 

Replaces one or more identifiers in the template with the specified value (or the value from the specified callback) if the name and the value of the identifier matches the arguments.

Template::replaceIdentifierCallback (   $sIdentifier,
  $sCallbackMethod = null,
  $iFlags = 0 
Template::replaceIdentifierMultiple (   $mIdentifier,
  $mText = null,
  $sValue = TemplateIdentifier::PARAMETER_EMPTY_VALUE,
  $iFlags = 0,
  $mFunction = null 

Replaces one or more identifiers in the template with the specified value (or the value from the specified callback) if the name and the value of the identifier matches the arguments. In contrast to a simple replaceIdentifier call, calling this will preserve the identifiers at their locations for future replacement (after the current replacement).

Template::replaceIdentifierMultipleCallback (   $sIdentifier,
  $sCallbackMethod = "getTextForReplaceIdentifier",

Member Data Documentation

const Template::CONVERT_NEWLINES_TO_BR = 1024

This will run nl2br() on the replacement.

const Template::ESCAPE = 2

Escapes (quotes) all Javascript-unsafe characters

const Template::FORCE_HTML_ESCAPE = 16

Forces html-escaping of replacement values (even if the replacement is a template)

const Template::JAVASCRIPT_CONVERT = 4

Puts double-quotes around the string. Only used in conjunction with ESCAPE

const Template::JAVASCRIPT_ESCAPE = 7


const Template::LEAVE_IDENTIFIERS = 8

Re-use existing identifiers (if the replacing value is a template) or re-parse identifier-like strings (if the replacement is a string)

const Template::NO_HTML_ESCAPE = 1

Prevents any HTML escaping from taking place (usually any replacement values except templates are being html-escaped).


A replaceIdentifier… operation with this flag set will not look inside template identifier values or parameters for inner identifiers to be replaced. Use this e.g. to to a quicker replacement when you’re sure you don’t have any relevant inner identifiers.

const Template::NO_NEW_CONTEXT = 64

Does not duplicate the context when doing multiple replacements on the same identifier. This means that the {{identifierContext}} can be used to mark an area to be deleted if no replacements occur but still keep the area only once if multiple replacements happen.

const Template::NO_NEWLINE = 32

Suppresses the printing of a newline character between multiple replacements of the same identifier

const Template::NO_RECODE = 256

This will not do any charset-conversions. This only affects operation where the replacement is another template.

const Template::STRIP_TAGS = 512

This will run strip_tags() on the replacement.

const Template::URL_ENCODE = 2048

This will run urlencode() on the replacement.

The documentation for this class was generated from the following file: