Smarty::setTemplateDir PHP Method

setTemplateDir() public method

Set template directory
public setTemplateDir ( string | array $template_dir ) : Smarty
$template_dir string | array directory(s) of template sources
return Smarty current Smarty instance for chaining
    public function setTemplateDir($template_dir)
    {
        $this->template_dir = array();
        foreach ((array) $template_dir as $k => $v) {
            $this->template_dir[$k] = str_replace(array('//', '\\\\'), DS, rtrim($v, '/\\')) . DS;
        }
        $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
        return $this;
    }

Usage Example

Example #1
0
 function renderEntries(Search_ResultSet $entries)
 {
     global $tikipath;
     $smarty = new Smarty();
     $smarty->setCompileDir($tikipath . 'templates_c');
     $smarty->setTemplateDir(null);
     $smarty->setTemplateDir(dirname($this->templateFile));
     $smarty->setPluginsDir(array($tikipath . TIKI_SMARTY_DIR, SMARTY_DIR . 'plugins'));
     $secpol = new Tiki_Security_Policy($smarty);
     $secpol->secure_dir[] = dirname($this->templateFile);
     $smarty->enableSecurity($secpol);
     if ($this->changeDelimiters) {
         $smarty->left_delimiter = '{{';
         $smarty->right_delimiter = '}}';
     }
     foreach ($this->data as $key => $value) {
         $smarty->assign($key, $value);
     }
     $smarty->assign('results', $entries);
     $smarty->assign('facets', array_map(function ($facet) {
         return array('name' => $facet->getName(), 'label' => $facet->getLabel(), 'options' => $facet->getOptions());
     }, $entries->getFacets()));
     $smarty->assign('count', count($entries));
     $smarty->assign('offset', $entries->getOffset());
     $smarty->assign('offsetplusone', $entries->getOffset() + 1);
     $smarty->assign('offsetplusmaxRecords', $entries->getOffset() + $entries->getMaxRecords());
     $smarty->assign('maxRecords', $entries->getMaxRecords());
     return $smarty->fetch($this->templateFile);
 }
All Usage Examples Of Smarty::setTemplateDir