コード例 #1
0
 public static function getView($key = 'default')
 {
     if (isset(self::$viewResMap[$key])) {
         return self::$viewResMap[$Key];
     }
     require_once FILE . "/component/smarty-3.1.24/libs/Smarty.class.php";
     $view = new Smarty();
     $view->setTemplateDir(FILE . cfg_template::$template_dir . $key);
     $view->setCompileDir(FILE . '/data/' . $key . cfg_template::$compile_dir);
     $view->setCacheDir(FILE . '/data/' . $key . cfg_template::$cache_dir);
     $view->setCaching(cfg_template::$caching);
     $view->setLeftDelimiter(cfg_template::$left_delimiter);
     $view->setRightDelimiter(cfg_template::$right_delimiter);
     self::$viewResMap[$key] = $view;
     return self::$viewResMap[$key];
 }
コード例 #2
0
ファイル: index.php プロジェクト: sexdevil/gulp-her-webapp
function render_smarty($tpl = null, $data = array())
{
    $root = dirname(__FILE__) . '/';
    if (!$tpl) {
        $path = $_SERVER['REQUEST_URI'];
        $split = explode('/', $path);
        $last = array_pop($split);
        $len = count($split);
        if (($pos = strpos($path, '?')) !== false) {
            $path = substr($path, 0, $pos);
        }
        if (1 === $len) {
            $path .= '/index.tpl';
        } else {
            $path .= '.tpl';
        }
        $tpl = $root . 'template' . $path;
    }
    if (!file_exists($tpl)) {
        echo "404 Not Found";
        exit;
    }
    $data_path = str_replace('/template', '/test', $tpl);
    $data_path = str_replace('.tpl', '.php', $data_path);
    require_once $root . 'libs/smarty/Smarty.class.php';
    $smarty = new Smarty();
    $default_conf = array('template_dir' => 'template', 'config_dir' => 'config', 'plugins_dir' => array('libs/Bigpipe/runtime/plugins'), 'left_delimiter' => '{%', 'right_delimiter' => '%}');
    $smarty->setTemplateDir($root . $default_conf['template_dir']);
    $smarty->setConfigDir($root . $default_conf['config_dir']);
    foreach ($default_conf['plugins_dir'] as $dir) {
        $smarty->addPluginsDir($root . $dir);
    }
    $smarty->setLeftDelimiter($default_conf['left_delimiter']);
    $smarty->setRightDelimiter($default_conf['right_delimiter']);
    if (file_exists($data_path)) {
        require_once $data_path;
        $smarty->assign($fis_data);
    }
    $smarty->display($tpl);
}
コード例 #3
0
ファイル: SmartyEngine.php プロジェクト: latrell/smarty
 /**
  * Get the evaluated contents of the view at the given path.
  *
  * @param string $path
  * @param array $data
  * @return string
  */
 protected function evaluatePath($__path, $__data)
 {
     $caching = $this->config('caching');
     $cache_lifetime = $this->config('cache_lifetime');
     $debugging = $this->config('debugging');
     $template_path = $this->config('template_path');
     $compile_path = $this->config('compile_path');
     $cache_path = $this->config('cache_path');
     $plugins_paths = (array) $this->config('plugins_paths');
     $config_paths = (array) $this->config('config_paths');
     $escape_html = $this->config('escape_html', false);
     $leftDelimiter = $this->config('left_delimiter', '{');
     $rightDelimiter = $this->config('right_delimiter', '}');
     // Create smarty object.
     $smarty = new \Smarty();
     $smarty->setTemplateDir($template_path);
     $smarty->setCompileDir($compile_path);
     $smarty->setCacheDir($cache_path);
     foreach ($plugins_paths as $path) {
         $smarty->addPluginsDir($path);
     }
     foreach ($config_paths as $path) {
         $smarty->setConfigDir($path);
     }
     $smarty->debugging = $debugging;
     $smarty->caching = $caching;
     $smarty->cache_lifetime = $cache_lifetime;
     $smarty->compile_check = true;
     // set the escape_html flag from the configuration value
     //
     $smarty->escape_html = $escape_html;
     $smarty->error_reporting = E_ALL & ~E_NOTICE;
     $smarty->setLeftDelimiter($leftDelimiter);
     $smarty->setRightDelimiter($rightDelimiter);
     foreach ($__data as $var => $val) {
         $smarty->assign($var, $val);
     }
     return $smarty->fetch($__path);
 }
コード例 #4
0
ファイル: setting.inc.php プロジェクト: VampireMe/Common_PHP
<?php

/**
 * 共有引用文件
 * @author gaoqing
 * 2015-09-04
 */
require_once './class/Smarty.class.php';
/*
 * 1、实例化 Smarty 对象
 * 2、设置其参数
 */
//1、实例化 Smarty 对象
$smarty = new Smarty();
//2、设置其参数
$smarty->setConfigDir("config.conf");
$smarty->setTemplateDir("tpl");
$smarty->setCompileDir("tpl_c");
$smarty->addPluginsDir("plugins");
$smarty->setLeftDelimiter("<{");
$smarty->setRightDelimiter("}>");
$smarty->setAutoLiteral(false);