Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 499

Notice: Undefined offset: 8192 in /home/miphpf/domains/miphpf.com/public_html/includes/common.inc on line 506

Warning: Incorrect key file for table './miphpf_miphpfcom/watchdog.MYI'; try to repair it query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.', 2, '', 'http://www.miphpf.com/manual/template_parser.html', '', '18.223.205.61', 1713494103) in /home/miphpf/domains/miphpf.com/public_html/includes/database.mysql.inc on line 121
Template Parser | MIPHPF - Your Open Source RAD PHP Framework
Skip navigation.
Home

Template Parser

: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/miphpf/domains/miphpf.com/public_html/includes/unicode.inc on line 291.

The template parser parses file contents and replaces the template variables with their values. It supports sections, the sections could be nested. The number of times a section is shown is controlled from the PHP code. There is no logic in the template file.

It is convention, but not a requirement, to use template variables in the form %%VAR%%. This helps to spot the template variables easier in the template file.

* Example:

<?php
    $t
= new miTemplateParser();
   
$t->readTemplate('template.tmpl');
   
$t->assign('%%VAR%%', 'test value');
   
$t->templateShow();
?>

Template:
<span  style="color: #ff0000">%%VAR%%</span>
Result:
<span  style="color: #ff0000">test value</span>

Subsection example:

<?php
$section
= new miTemplateParserSectionInfo();
$section->setSectionInfo('test1', 1, array('%%VAR1%%' => 'a variable'));

$t = new miTemplateParser();
$t->setSectionInfos(array($section));
$t->templateShow();
?>

Template: <mi:section name="test1">%%VAR1%%</mi:section>
Result:
a variable
* Multiple subsections example:
<?php
$section
= new miTemplateParserSectionInfo();
$section->setSectionInfo('test4', 1);
$subSectionA = new miTemplateParserSectionInfo();
$subSectionA->setSectionInfo('subtest4a', 1, array('%%SUBSECTION_VAR%%' => 'subsection var'));
$subSectionB = new miTemplateParserSectionInfo();
$subSectionB->setSectionInfo('subtest4b', 1);
$section->addSubsection($test4SubSectionA);
$section->addSubsection($test4SubSectionB);

$t = new miTemplateParser();
$t->setSectionInfos(array($section));
$t->templateShow();
?>

Template:
<mi:section name="test4">
<p><mi:section name="subtest4a">%%SUBSECTION_VAR%%</mi:section></p>
<p><mi:section name="subtest4b">subsection 4b</mi:section></p>
</mi:section>
Result:
<p>subsection var</p>
<p>subsection 4b</p>