Skip to content

Commit 8bb5e30

Browse files
authored
Merge pull request #22 from Elma/new_option_and_global_opttions
Add `check_placeholder_exists` option and `setGlobalOptions` method
2 parents 002f7d7 + 5a8b972 commit 8bb5e30

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

HTML/Template/IT.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,12 @@ class HTML_Template_IT
389389
var $_options = array(
390390
'preserve_data' => false,
391391
'use_preg' => true,
392-
'preserve_input'=> true
392+
'preserve_input'=> true,
393+
'check_placeholder_exists' => true,
393394
);
394395

396+
public static $globalOptions = [];
397+
395398
/**
396399
* Builds some complex regular expressions and optionally sets the
397400
* file root directory.
@@ -408,6 +411,9 @@ class HTML_Template_IT
408411
*/
409412
function __construct($root = '', $options = null)
410413
{
414+
if (!empty(self::$globalOptions)) {
415+
$this->setOptions(self::$globalOptions);
416+
}
411417
if (!is_null($options)) {
412418
$this->setOptions($options);
413419
}
@@ -481,6 +487,16 @@ function setOptions($options)
481487
return IT_OK;
482488
}
483489

490+
/**
491+
* Define global options used for all new instances.
492+
* options defined using constructor parameter will overwrite
493+
* globalOptions
494+
*/
495+
public static function setGlobalOptions($options)
496+
{
497+
self::$globalOptions = $options;
498+
}
499+
484500
/**
485501
* Print a certain block with all replacements done.
486502
*
@@ -766,7 +782,7 @@ function setVariable($variable, $value = '')
766782
$this->setVariable($key, $value);
767783
}
768784
} else {
769-
if ($this->checkPlaceholderExists($this->currentBlock, $variable)) {
785+
if (!$this->_options['check_placeholder_exists'] || $this->checkPlaceholderExists($this->currentBlock, $variable)) {
770786
$this->variableCache[$variable] = $value;
771787
}
772788
}

0 commit comments

Comments
 (0)