Example #1
0
 /**
  * Called automatically during init for template initalization.
  *
  * @param string       $template_spot   Where object's output goes
  * @param string|array $template_branch Where objects gets it's template
  *
  * @return AbstractView $this
  *
  * @internal
  */
 public function initializeTemplate($template_spot = null, $template_branch = null)
 {
     if ($template_spot === null) {
         $template_spot = $this->defaultSpot();
     }
     $this->spot = $template_spot;
     if (@$this->owner->template && !$this->owner->template->is_set($this->spot)) {
         throw $this->owner->template->exception('Spot is not found in owner\'s template')->addMoreInfo('spot', $this->spot);
     }
     if (!isset($template_branch)) {
         $template_branch = $this->defaultTemplate();
     }
     if (isset($template_branch)) {
         // template branch would tell us what kind of template we have to
         // use. Let's look at several cases:
         if (is_object($template_branch)) {
             // it might be already template instance (object)
             $this->template = $template_branch;
         } elseif (is_array($template_branch)) {
             // it might be array with [0]=template, [1]=tag
             if (is_object($template_branch[0])) {
                 // if [0] is object, we'll use that
                 $this->template = $template_branch[0];
             } else {
                 $this->template = $this->app->add('Template');
                 /** @type Template $this->template */
                 $this->template->loadTemplate($template_branch[0]);
             }
             // Now that we loaded it, let's see which tag we need to cut out
             $this->template = $this->template->cloneRegion(isset($template_branch[1]) ? $template_branch[1] : '_top');
         } else {
             // brach could be just a string - a region to clone off parent
             if (isset($this->owner->template)) {
                 $this->template = $this->owner->template->cloneRegion($template_branch);
             } else {
                 $this->template = $this->add('Template');
             }
         }
         /** @type Template $this->template */
         $this->template->owner = $this;
     }
     // Now that the template is loaded, let's take care of parent's template
     if ($this->owner && isset($this->owner->template) && !empty($this->owner->template)) {
         $this->owner->template->del($this->spot);
     }
     // Cool, now let's set _name of this template
     if ($this->template) {
         $this->template->trySet('_name', $this->getJSID());
     }
 }
Example #2
0
File: Web.php Project: atk4/atk4
 /**
  * Called on all templates in the system, populates some system-wide tags.
  *
  * @param Template $t
  */
 public function setTags($t)
 {
     // Determine Location to atk_public
     if ($this->app->pathfinder && $this->app->pathfinder->atk_public) {
         $q = $this->app->pathfinder->atk_public->getURL();
     } else {
         $q = 'http://www.agiletoolkit.org/';
     }
     $t->trySet('atk_path', $q . '/');
     $t->trySet('base_path', $q = $this->app->pm->base_path);
     // We are using new capability of SMlite to process tags individually
     try {
         $t->eachTag($tag = 'template', array($this, '_locateTemplate'));
         $t->eachTag($tag = 'public', array($this, '_locatePublic'));
         $t->eachTag($tag = 'js', array($this, '_locateJS'));
         $t->eachTag($tag = 'css', array($this, '_locateCSS'));
         $t->eachTag($tag = 'page', array($this, '_locatePage'));
     } catch (BaseException $e) {
         throw $e->addMoreInfo('processing_tag', $tag)->addMoreInfo('template', $t->template_file);
     }
     $this->hook('set-tags', array($t));
 }
Example #3
0
File: Lister.php Project: atk4/atk4
 /**
  * Renders single row.
  *
  * If you use for formatting then interact with template->set() directly
  * prior to calling parent
  *
  * @param Template $template template to use for row rendering
  *
  * @return string HTML of rendered template
  */
 public function rowRender($template)
 {
     foreach ($this->current_row as $key => $val) {
         if (isset($this->current_row_html[$key])) {
             continue;
         }
         $template->trySet($key, $val);
     }
     $template->setHTML($this->current_row_html);
     $template->trySet('id', $this->current_id);
     $o = $template->render();
     foreach (array_keys($this->current_row) + array_keys($this->current_row_html) as $k) {
         $template->tryDel($k);
     }
     return $o;
 }