Exemplo n.º 1
0
 /**
  * Sets a variable and its value.
  *
  * The variable will be extracted to the local scope of the template with
  * the same name given as parameter to the method. So setting a variable
  * named "title" will result in a $title variable available to the template.
  *
  * The value can be a string, a number or a PhpTemplate instance. In the
  * latter case, the variable content will be the result of the whole parsed
  * template of the PhpTemplate instance.
  *
  * The proper method for setting arrays is setArray().
  *
  * @since 1.1
  * @param string $name Name of the variable.
  * @param string|number|PhpTemplate $value variable content.
  * @see setArray()
  */
 public function set($name, $value)
 {
     if ($value instanceof \Innomatic\Tpl\Template) {
         // This is a subtemplate, process it.
         //
         $this->vars[$name] = $value->parse();
     } elseif (is_array($value)) {
         // This is an array, it must be passed encoded.
         //
         $this->vars[$name] = $value;
         $this->tplEngine->set($name, \Shared\Wui\WuiXml::encode($value));
     } elseif (is_numeric($value)) {
         // This is a number, it must be passed as it is.
         //
         $this->vars[$name] = $value;
         $this->tplEngine->set($name, $value);
     } else {
         // This is a string, it must be passed as a CDATA.
         //
         $this->vars[$name] = $value;
         $this->tplEngine->set($name, \Shared\Wui\WuiXml::cdata($value));
     }
 }
Exemplo n.º 2
0
 /**
  * Sets a variable and its value.
  *
  * The variable will be extracted to the local scope of the template with
  * the same name given as parameter to the method. So setting a variable
  * named "title" will result in a $title variable available to the template.
  *
  * The value can be a string, a number or a PhpTemplate instance. In the
  * latter case, the variable content will be the result of the whole parsed
  * template of the PhpTemplate instance.
  *
  * The proper method for setting arrays is setArray().
  *
  * @since 1.1
  * @param string $name Name of the variable.
  * @param string|number|PhpTemplate $value variable content.
  * @see setArray()
  */
 public function set($name, $value)
 {
     $this->vars[$name] = $value instanceof \Innomatic\Tpl\Template ? $value->parse() : $value;
 }