finally called the two-line statements of parse () and P () to be merged into a shorthand function pparse ():
pparse ("Myfinaloutput", "Secondhandle");
The
of another phplib template is that the Set_file () and Set_var () functions can also receive multiple sets of values at a time by passing a handle/array
You can pass a third argument to parse () and Pparse () if you want to append data to the template variable instead of replacing it. can be simply
uses true as the third parameter to invoke parse () and Pparse (), such as: <?php
$t->parse ("Myoutput", "Myfilehandle", true);
?>
If the myoutput already contains the data, Myfilehandle will be parsed and appended to the myoutput already existing data. This technique is very useful, if you already have a template, you want the same piece of text to be repeated multiple times, such as listing multiple rows in a database query result. You may also be displaying the variables in the array, as in the following example:
<?php
$t = new Template ("/home/mydir/mytemplates/"); $t->set_file (Array ("MainPage" => "mainpage.ihtml", "Each_element" => "each_element.ihtml")), Reset ($myArray while ($elementName, $elementValue) = each ($myArray)) {
//Set ' value ' and ' name ' for the values and names of each element
This example uses two templates, mainpage.ihtml and each_element.ihtml. mainpage.ihtml template may be like this:
is the array:
{array_elements}
The {array_elements} tag above the
will be replaced by a each_element.ihtml copy, which will be heavy based on the array ($myArray)
Complex. The each_element.ihtml template may look like this:
{Name}: {Value}
The result of
processing is a well-formed table containing $myarray elements. But it's better if you combine two templates into one template
? In fact, they can be combined using template blocks. The template block allows you to remove a piece of text from a template, so you can repeat it very
many times, or do whatever you want on it. But I will cover this feature in another article.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service