Location: PHPKode > projects > ExTemplates Library > TemplateBlock.php
<?

/*
This script is a part of the ExTemplates Library
Author: Alexander Netkachev

Check the license.txt for copyright and terms.
*/


class TemplateBlock {
  var $visible;
  var $content;
  var $beforeRender;
  var $afterRender;
  var $name;

  function TemplateBlock(&$array, $name) {
    $this->content = &$array;
    $this->visible = true;
    $this->name = $name;
  }

  function isVisible() {
    return $this->visible;
  }

  function setVisible($visible) {
    $this->visible = ($visible === true);
  }

  function render() {
    $result = '';
    if (strlen($this->beforeRender) != 0) {
      $eventHandlerName = $this->beforeRender;
      $eventHandlerName($this);
    }
    if ($this->visible) {
      $keys = array_keys($this->content);
      foreach ($keys as $key) {
        if (gettype($this->content[$key]) == 'object') {
          $control = & $this->content[$key];
          $result .= $control->render();
        } else
            $result .= $this->content[$key];
      }
    }
    if (strlen($this->afterRender) != 0) {
      $eventHandlerName = $this->afterRender;
      $result = $eventHandlerName($this, $result);
    }
    return $result;
  }

  function & getControl($name) {
    return $this->content[$name];
  }

  function setVariable($name, $value) {
    $this->content[$name] = $value;
  }
}

?>
Return current item: ExTemplates Library