// from:
http://www.4kiki.net/php_lib_template/
PHPLIB Template Template Chinese Documentation First Edition 2004-10-16
IWIND translation (2004-10-24 update)
Chapter 10. Template (Template)
table of Contents
Template class instance variable
Template class instance method
Method for calling
Internal instance method
Template application example
Remarks: If you think it is like fastTemplates, then you have to read it carefully, in fact it is not.
This template class allows you to retain HTML code in some external files, which do not contain PHP code, only with a field (translation note:) "reference"). This class provides some functions that allow you to replace fields with any string.
Note: The version of the document is no longer maintained, see the comment section in the template.inc source file to get the most reliable document.
Template class instance variable
Calling instance variable
ClassName string (String). Class sequence help: Class name .debug integer (INTEGER). Identification: Set to 1 Observe all variable assignment case, set to 2 Observer can call variable, set to 4 Observe internal function call .unknowns is one of the three of "Keep", "Comment", "Remove". Decide how to handle the number of variable names that have not completed in the template on the output link. If set to "Keep", these variable names will The original reservation is reserved. If set to "comment", then the number of unfinished variable names will be converted to HTML. If set to "remove", the name of the unfinished variable will be Silled (this is also the default situation) .halt_on_error = "YES" is one of the three of "YES", "Report", "NO". Decide the template class error handling method. Such as "Yes" (By default), the error will be reported, the program execution is also broken. If set to "Report", the error will also be reported, but the program continues to execute, and return "false". If set to "no", error Blocked, the program execution result returns "false" last_error = "" The most recent error message is saved inside this variable.
Internal instance variable
File string, a conversion table, can convert the variable name into the corresponding file name. ROOT string (path name). Template file is loaded. VARKEYS string is aquarium. A conversion table, The variable name can be converted into a regular expression corresponding to it. Varvals string has a column. One conversion table can convert the variable name into their respective VARKEY corresponding alternative values.
Template class instance method can call an instance method
Template ($ root = ", $ unknowns =" remove ") constructor. You can have two optional parameters. The first song parameter setting template is located, the second parameter sets the processing method of unknown variables.
Set_root ($ root) This function checks if the Root is a valid directory, then stores this template to the eye .Set_unknowns ($ unknowns = "limited") This function sets the unprocessed variable name processing method It must be one of "Remove", "Comment" or "Keep". If set to "Keep", these variable names will remain unchanging. If set to "comment", then it will be reported. At the same time, the number of variables that have not been processed is all converted to the HTML annotation. If set to "Remove", the name of the unfinished variable will be quietly deleted (this is the default).
Set_file ($ VARNAME, $ filename = ") This function defines a file name for a function, you can call it with a $ VarName / $ FileName or a series of $ VarName / $ FileName. These files are only It will be loaded when needed .SET_BLOCK ($ PARENT, $ VARNAME, $ Name = ") Variable $ PARENT can include a variable block named $ VarName. This function removes this block from $ PARENT, then use A variable named $ name instead of it. If $ name is ignored, then it will be assumed to be the same as $ VarName.
Set_var ($ VARNAME, $ VALUE = ") This function sets the initial value of a variable. You can call it with a $ VARNAME / $ VALUE or a series of $ VarName / $ VALUE pairs.
Subst ($ VARNAME) This function returns a value named $ VarName, all of which has been filled with the value of the defined variable. The result string is not the final result, but the process of unpleassed variables has not been applied. result.
PSUBST ($ VarName)
This is a short written form of Print $ this-> Subst ($ VarName).
PARSE ($ TARGET, $ VARNAME, $ APPEND = false) This function replaces all the values of all defined variables in $ VarName, and stores or attaches the result of $ target as the variable name.
If $ VARNAME is a variable name, $ append will be blocked. The variable of $ VarName is continuously replaced, and the results of each alternative step are in $ target. The final alternative result can be named Target The variables are obtained, which can be considered as an intermediate processing link of the next $ VarName.
PPARSE ($ TARGET, $ VarName, $ append = false) This is a short writing form of Print $ this-> parse (...).
Get_vars () Returns all sequences to define values, each value, with its name.
Query_ID () Returns the value of the variable named by $ VarName. If the $ VarName corresponds to a file, and the file has not loaded, the variable will be reported empty. When the variable name is called, a value of the value will be returned, in which The name is key.
Get_undefined ($ VARNAME) This function returns a series of unprocessed variable names (ie a sequence containing $ A [$ Name] = $ Name) in a way that is not keys to VarName, Name.
FINISH ($ STR) This function will return the final version of $ STR, that is, the method for unstoppable processing will be applied to $ STR.
p ($ VARNAME) This function will output the value of the last version of the variable named by $ VarName.
GET ($ VARNAME) This function will get the last version of the variable named by $ VARNAME.
Haltmsg ($ msg) This function can be overwritten in your template subclass. It can output information used to call.
Internal instance method
FileName ($ filename) When calling with a relative path, the function returns a path name, with the appropriate directory name extracted from $ this-> root. If it is an absolute path, it is not used.
The result file name must be existing, otherwise it will live a mistake.
VarName ($ VARNAME) This function constructs a variable name expression based on the name of the variable name (Mode Note: That is, VAR -> {var}).
LoadFile ($ VARNAME) If a variable is not defined or empty, and corresponds to a file, the file corresponding to the file will be loaded, and the file content will be impeded to the value of the variable.
Halt ($ msg) Whenever a mistake occurs, this function will be evokeed and handled this error according to the $ this-> halt_on_error defined.
Template Application Instance This template class manages a collection of variables, which are text strings. These strings may include references to other variables in the form of {variable}. When analyzing or replacing, a variable will be quoted by that variable The value is replaced. For example, if you
PHP $ T = New Template; $ T-> set_var ("a", "defined as hugo"); $ t-> set_var ("b", "the value of a is {a}); Print $ T-> Subst ("b")?> "The value of a is defined as hugo" will output.
The value of a variable can be manually called set_var ('name "," value "), or may call set_file (" name "," filename.ihtml "); defined from a file. In the latter case In, when needed (as night) file content being loaded, and is set to the value of the variable.
The third definition variable value is to call set_block ("parent", "block", "name"); in this case, the variable name "Parent" is treated as For the beginning, the block ended with the end. The string is deleted from the variable "Parent", which is given to the "block" variable. In "Parent" "Name" corresponding variable references are replaced. If option "name" is left blank, "block" will be used to replace.
For example, if you write
php $ t = new template; $ t-> set_var ("a", "Front Matter this is block b end matter); $ T-> set_block ("a", "b", "bb");?>
The variable "a" is defined as "Front Matter {BB} end Matter", and the variable "b" is a block. All makes the tracking variable access is more when you set the internal variable debug 7 when you set up internal variable debugs. Clear. Use the template class directly or if necessary, define a child class of a template class.
Define a template file called page.ihtml like this.