[转] phplib template template Chinese documentation

xiaoxiao2021-03-06  39

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

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

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.

{pageTitle} </ title> </ head> <body bgcolor = "# ffffff"> <table border = 1 cellpadding = 4 cellspacing = 0 bgcolor = "# eeeeeeeee"> <TR> <TD COLSPAN = 2> <H1> {pageTitle} </ h1> </ td> </ tr> <tr> <td> {out} </ td> <td> content <br> {undefined_variable} </ td > </ TR> </ Table> </ body> </ html> This file contains a reference to the corresponding variable pagetitlet and a reference to OUT named. Another reference is not parsed by undefined_variable named variables. Another template File, named Box.IHTML, including a block named ROW, contains three variable references. {Title}, {Num} and {Bignum}:</p> <p><! - start box.ihtml -> <table border = 1 bgcolor = "# ccccc" cellpadding = 4 cellspacing = 0> <tr> <td colspan = 2> <b> {title} </ b> </ TD> </ tr> <tr> <td> {num} </ td> <td> {bignum} </ tr> <! - end}> </ TABLE > <! - end box.ihtml -> How to use these templates: <? php / * introduced template * / include ("template.inc"); / * Generate template classes with required parameters An instance object * / $ t = new template ("/ home / kris / www / test.koehntopp.de / pages / template", "keep"); / * $ t-> debug = 7; * / / * Activate all debug * / / * Define two variables from the file * / $ t-> set_file ("page" => "page.ihtml", "Box" => "box.ihtml")); / * Define variables contained in another variable * / $ t_block ("box", "row", "rows"); / * Manually define two variables * / $ t-> set_var (Array " => "Testseite", "PageTitle" => "hugo")); for ($ I = 1; $ I <= 3; $ i ) {$ n = $ i; $ nn = $ i * 10; / * Assign NUM and BIGNUM * / $ t-> set_var (array ("num" => $ n, "Bignum" => $ NN)); / * Replace NUM and BIGNUM * in ROW to attach results to ROWS * / $ T-> Parse ("Rows", "Row", True;} / * Replace all variables in the box, the result is stored in Out * / $ t-> parse ("out", array ("box", "Page"); / * Print out * / $ t-> p ("out");?> <hr> Output undefined variable: <? php print @ Ide (",", $ t-> get_u NDEfined ("out"));?></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-68790.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="68790" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.055</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'Bz0r8pOIcabC9EvvRaM_2FhrqIVzIH9_2F4WIBl1UcU8p2PITlG2DoIPEUUbbzdXyD5mKWLw_2Bi8wlo1DIKsKuv4KuQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>