scan vars in template
Open Document Templating System for PHP
Brought to you by:
cyruss666,
doctorrock
You could add this method to your class.
It can avoid to have errors with setVars()
class myOdfClass extends Odf
{
public function scanTemplate()
{
$subject = $this->__toString();
$pattern = '/.*\\'.parent::DELIMITER_LEFT.'(.*)\\'.parent::DELIMITER_RIGHT.'.*/mU';
preg_match_all($pattern, $subject, $matches);
return $matches[1];
}
}
// object instanciation
$odf = new myOdfClass ("tpl/myTemplate.odt");
// Get marks included in template
$marks = $odf->scanTemplate();
// Replace Vars/marks by values or NULL values
foreach ($marks as $val) {
if (isset($defaultVal[$val])) {
$odf->setVars($val, $defaultVal[$val]);
} else {
$odf->setVars($val, '');
}
} // end foreach ($marks ...