templateExists() public method

Check if a template resource exists
public templateExists ( string $resource_name ) : boolean
$resource_name string template name
return boolean status
 public function render($blockName, $moduleName, $controllerName, $actionName, $dataHolder = null, $defaultDir = null)
 {
     $smartyData = $this->smarty->createData($this->smarty);
     if ($dataHolder != null) {
         foreach ($dataHolder as $key => $value) {
             $smartyData->assign($key, $value);
         }
     }
     \org\equinox\utils\debug\DebugBarFactory::add($smartyData->getTemplateVars(), 'Smarty', $blockName);
     $this->smarty->setTemplateDir(ROOT . '/' . $this->templateDir);
     $template = $moduleName . '/' . $controllerName . '/' . $actionName;
     if (!$this->smarty->templateExists($template . '.tpl')) {
         // check the default template
         if ($defaultDir != null) {
             $this->smarty->setTemplateDir($defaultDir);
             $template = $controllerName . '/' . $actionName;
             if (!$this->smarty->templateExists($template . '.tpl')) {
                 throw new \org\equinox\exception\EquinoxException("Cannot find ({$template}.tpl) template in (" . ROOT . '/' . $this->templateDir . ") nor in default directory ({$defaultDir})");
             }
         } else {
             throw new \org\equinox\Exception\EquinoxException("Cannot find ({$template}.tpl) template in (" . $this->smarty->template_dir . ") and no default directory provided");
         }
     }
     $html = $this->smarty->fetch($template . '.tpl', $smartyData);
     \org\equinox\utils\debug\DebugBarFactory::add($html, 'Smarty', $blockName . '_html');
     return $html;
 }
Example #2
0
 /**
  * @param string $sTemplate
  * @param bool $bException
  *
  * @return bool|void
  * @throws Exception
  */
 protected function _tplTemplateExists($sTemplate, $bException = false)
 {
     if (!$this->oSmarty) {
         $this->_tplInit();
     }
     $bResult = $this->oSmarty->templateExists($sTemplate);
     $sSkin = $this->GetConfigSkin();
     if (!$bResult && $bException) {
         $sMessage = 'Can not find the template "' . $sTemplate . '" in skin "' . $sSkin . '"';
         if ($aTpls = $this->GetSmartyObject()->template_objects) {
             if (is_array($aTpls)) {
                 $sMessage .= ' (from: ';
                 foreach ($aTpls as $oTpl) {
                     $sMessage .= $oTpl->template_resource . '; ';
                 }
                 $sMessage .= ')';
             }
         }
         $sMessage .= '. ';
         $oSkin = E::ModuleSkin()->GetSkin($sSkin);
         if ((!$oSkin || $oSkin->GetCompatible() != 'alto') && !E::ActivePlugin('ls')) {
             $sMessage .= 'Probably you need to activate plugin "Ls".';
         }
         // записываем доп. информацию - пути к шаблонам Smarty
         $sErrorInfo = 'Template Dirs: ' . implode('; ', $this->oSmarty->getTemplateDir());
         $this->_error($sMessage, $sErrorInfo);
         return false;
     }
     if ($bResult && ($sResult = $this->_getTemplatePath($sSkin, $sTemplate))) {
         $sTemplate = $sResult;
     }
     return $bResult ? $sTemplate : $bResult;
 }
Example #3
0
/**
 * Smarty Help Tag
 * Displays help text of this module.
 *
 * Examples:
 * <pre>
 * {help}
 * </pre>
 *
 * Type:     function<br>
 * Name:     help<br>
 * Purpose:  displays help.tpl for a module, if existing<br>
 *
 * @param array  $params
 * @param Smarty $smarty
 *
 * @return string
 */
function Smarty_function_help($params, $smarty)
{
    $modulename = $smarty->getTemplateVars('template_of_module');
    $tpl = $modulename . '/view/smarty/help.tpl';
    // load the help template from the module path ->  app/modules/modulename/view/help.tpl
    if ($smarty->templateExists($tpl)) {
        return $smarty->fetch($tpl);
    }
    return 'Help Template not found.';
}
Example #4
0
/**
 * Smarty pagination
 * Displays a pagination Element.
 *
 * Examples:
 * <pre>
 * {pagination}
 * </pre>
 *
 * Type:     function<br>
 * Name:     pagination<br>
 * Purpose:  display pagination if needed<br>
 *
 * @param array  $params
 * @param Smarty $smarty
 *
 * @return string
 */
function smarty_function_pagination($params, $smarty)
{
    // check if a alphabet pagination is requested
    if (isset($params['type']) and $params['type'] === 'alphabet') {
        // check if file exists
        if ($smarty->templateExists('pagination-alphabet.tpl') === false) {
            echo 'Pagination Template for alphabet not found.';
        } else {
            // load the generic pagination template
            return $smarty->fetch('pagination-alphabet.tpl');
        }
    }
    // check if file exists
    if ($smarty->templateExists('pagination-generic.tpl') === false) {
        echo 'Pagination Template not found.';
    } else {
        // load the generic pagination template
        return $smarty->fetch('pagination-generic.tpl');
    }
}
Example #5
0
/**
 * Плагин для смарти
 * Подключает обработчик блоков шаблона
 *
 * @param array $aParams
 * @param Smarty $oSmarty
 * @return string
 */
function smarty_insert_block($aParams, &$oSmarty)
{
    /**
     * Устанавливаем шаблон
     */
    $sBlock = ucfirst(basename($aParams['block']));
    /**
     * Проверяем наличие шаблона. Определяем значения параметров работы в зависимости от того,
     * принадлежит ли блок одному из плагинов, или является пользовательским классом движка
     */
    if (isset($aParams['params']) and isset($aParams['params']['plugin'])) {
        $sBlockTemplate = Plugin::GetTemplatePath($aParams['params']['plugin']) . '/blocks/block.' . $aParams['block'] . '.tpl';
        $sBlock = 'Plugin' . ucfirst($aParams['params']['plugin']) . '_Block' . $sBlock;
    } else {
        $sBlockTemplate = Engine::getInstance()->Plugin_GetDelegate('template', 'blocks/block.' . $aParams['block'] . '.tpl');
        $sBlock = 'Block' . $sBlock;
    }
    $sBlock = Engine::getInstance()->Plugin_GetDelegate('block', $sBlock);
    if (!isset($aParams['block']) or !$oSmarty->templateExists($sBlockTemplate)) {
        trigger_error("Not found template for block: " . $sBlockTemplate, E_USER_WARNING);
        return;
    }
    /**
     * параметры
     */
    $aParamsBlock = array();
    if (isset($aParams['params'])) {
        $aParamsBlock = $aParams['params'];
    }
    /**
     * Подключаем необходимый обработчик
     */
    $oBlock = new $sBlock($aParamsBlock);
    /**
     * Запускаем обработчик
     */
    $oBlock->Exec();
    /**
     * Возвращаем результат в виде обработанного шаблона блока
     */
    return $oSmarty->fetch($sBlockTemplate);
}
Example #6
0
 /**
  * Checks to see if the named template exists
  *
  * @param string $name The template to look for
  * @return bool
  */
 public function templateExists($name)
 {
     return $this->_smarty->templateExists($this->resolveTemplate($name));
 }
Example #7
0
 /**
  * Проверяет существование шаблона
  *
  * @param string $sTemplate
  * @return bool
  */
 public function TemplateExists($sTemplate)
 {
     return $this->oSmarty->templateExists($sTemplate);
 }
Example #8
0
 /**
  * Checks to see if the named template exists
  *
  * @param string $name The template to look for
  * @return boolean
  */
 public function templateExists($name)
 {
     return $this->_smarty->templateExists($name);
 }
Example #9
0
 /**
  * Основной метод, выполняющий загрузку содержимого тестовой страницы
  */
 private function getContentImpl(RequestArrayAdapter $params, Smarty $smarty)
 {
     //Силовые упражнения
     $exId = $params->int('ex_id');
     if ($exId) {
         //$ex = GymManager::getInstance()->getExercise($exId);
         $tplPath = "gym/exercises/{$exId}.tpl";
         return $smarty->templateExists($tplPath) ? $smarty->fetch($tplPath) : null;
     }
     //Специальные страницы
     $pageType = $params->str('pagetype');
     if ($pageType) {
         $smParams = array();
         switch ($pageType) {
             case 'smarty':
                 foreach (array('blocks', 'functions', 'modifiers') as $type) {
                     $items = DirManager::smarty('plugins/' . $type)->getDirContentFull(null, PsConst::EXT_PHP);
                     /* @var $item DirItem */
                     foreach ($items as $item) {
                         //Название
                         $name = explode('.', $item->getName());
                         $name = $name[1];
                         //Первый комментарий
                         $tokens = token_get_all($item->getFileContents());
                         $comment = array(T_COMMENT, T_DOC_COMMENT);
                         $fileComment = '';
                         foreach ($tokens as $token) {
                             if (in_array($token[0], $comment)) {
                                 $fileComment = trim($token[1]);
                                 break;
                             }
                         }
                         $smParams[$type][] = array('name' => $name, 'comment' => $fileComment);
                     }
                 }
                 break;
             case 'doubleimg':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES);
                 $sorted = array();
                 /* @var $img DirItem */
                 foreach ($images as $img) {
                     $ident = $img->getSize() . 'x' . $img->getImageAdapter()->getWidth() . 'x' . $img->getImageAdapter()->getHeight();
                     $sorted[$ident][] = $img;
                 }
                 $result = array();
                 /* @var $img DirItem */
                 foreach ($sorted as $ident => $imgs) {
                     if (count($imgs) > 1) {
                         $result[$ident] = $imgs;
                     }
                 }
                 $smParams = array('images' => $result);
                 break;
             case 'testmethods':
                 $smParams['methods'] = TestManagerCaller::getMethodsList();
                 break;
             case 'imgbysize':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES, array('GymExercises'));
                 DirItemSorter::inst()->sort($images, DirItemSorter::BY_SIZE);
                 $smParams = array('images' => $images);
                 break;
             case 'formules':
                 $formules = TexImager::inst()->getAllFormules();
                 $totalSize = 0;
                 /* @var $formula DirItem */
                 foreach ($formules as $formula) {
                     $totalSize += $formula->getSize();
                     $formula->setData('class', 'TeX');
                 }
                 DirItemSorter::inst()->sort($formules, DirItemSorter::BY_SIZE);
                 $smParams = array('formules' => $formules, 'formules_size' => $totalSize);
                 break;
         }
         $content = $smarty->fetch("test/page_{$pageType}.tpl", $smParams);
         if ($pageType) {
             switch ($pageType) {
                 case 'patterns':
                     $out = array();
                     preg_match_all("/===(.*?)===/", $content, $out, PREG_PATTERN_ORDER);
                     $params = array();
                     for ($i = 0; $i < count($out[0]); $i++) {
                         $full = $out[0][$i];
                         $ctt = $out[1][$i];
                         $params[$full] = "<div class=\"demo-head\">{$ctt}</div>";
                     }
                     $content = PsStrings::replaceMap($content, $params);
             }
         }
         return $content;
     }
     //Тестовая страница
     $num = $params->int('num');
     $num = $num ? $num : 1;
     return $smarty->fetch("test/page{$num}.tpl");
 }
Example #10
0
<?php

//Подключили библиотеку simple_html_dom_parser.php
require_once "inc/simple_html_dom.php";
//Подключили автолоадер composer`a
require './vendor/autoload.php';
//Подключили наши функции
require_once "inc/functions.inc.php";
//Подключили скрипт парсера
require_once "inc/parser.inc.php";
//Создали объект для шаблонизатора
$smarty = new Smarty();
//Передаем параметры(результаты работы парсера)
$smarty->assign("teams", $teams);
$smarty->assign("links_for_teams_preview", $links_for_teams_preview);
$smarty->assign("last_tour_results", $last_tour_results);
//Проверяем существует ли шаблон
if (!$smarty->templateExists('data.tpl')) {
    exit('Такого шаблона не существует');
} else {
    $smarty->display("data.tpl");
}
<?php

require_once "vendor/autoload.php";
require_once "inc/cURL.inc.php";
require_once "inc/html_Parser.inc.php";
//Создаем экземпляр шаблонизатора.
$smarty = new Smarty();
//Передаем данные из парсера (html_Parser.inc.php) в шаблон
$smarty->assign("data", $total_game_data);
//Проверяем существует ли шаблон
if (!$smarty->templateExists('freerolls.tpl')) {
    exit('Такого шаблона не существует');
} else {
    $smarty->display("freerolls.tpl");
}