From 5a8b972317ea3210314be379c1d2acaa394a2e41 Mon Sep 17 00:00:00 2001 From: Guillaume Luchet Date: Mon, 8 Sep 2025 15:26:01 +0200 Subject: [PATCH] add check_placeholder_exists option to not check if a placeholder exists and add a setGlobalOptions method --- HTML/Template/IT.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/HTML/Template/IT.php b/HTML/Template/IT.php index ce72d6d..847652c 100755 --- a/HTML/Template/IT.php +++ b/HTML/Template/IT.php @@ -389,9 +389,12 @@ class HTML_Template_IT var $_options = array( 'preserve_data' => false, 'use_preg' => true, - 'preserve_input'=> true + 'preserve_input'=> true, + 'check_placeholder_exists' => true, ); + public static $globalOptions = []; + /** * Builds some complex regular expressions and optionally sets the * file root directory. @@ -408,6 +411,9 @@ class HTML_Template_IT */ function __construct($root = '', $options = null) { + if (!empty(self::$globalOptions)) { + $this->setOptions(self::$globalOptions); + } if (!is_null($options)) { $this->setOptions($options); } @@ -481,6 +487,16 @@ function setOptions($options) return IT_OK; } + /** + * Define global options used for all new instances. + * options defined using constructor parameter will overwrite + * globalOptions + */ + public static function setGlobalOptions($options) + { + self::$globalOptions = $options; + } + /** * Print a certain block with all replacements done. * @@ -766,7 +782,7 @@ function setVariable($variable, $value = '') $this->setVariable($key, $value); } } else { - if ($this->checkPlaceholderExists($this->currentBlock, $variable)) { + if (!$this->_options['check_placeholder_exists'] || $this->checkPlaceholderExists($this->currentBlock, $variable)) { $this->variableCache[$variable] = $value; } }