Кто знает SMARTY шаблоны TPL помогите разобраться?

12
anton000
На сайте с 10.05.2013
Offline
32
3963

У меня стоит Open Server, php 5.4, mySQL.

Я скачал smarty с офф. сайта. Распоковал в такую директорию: C:\open\OpenServer\domains\local

( local - это название сайта ). Далее сделал 4 папки templates и templates_c и cache и config.

Пути у них такие: C:\open\OpenServer\domains\local\templates ( аналогичные ).

Далее создал файл test.tpl в C:\open\OpenServer\domains\local\templates\test.tpl --- В него поместил --- Привет, {$name}!

Далее создал файл: smarty-test в C:\open\OpenServer\domains\local\smarty-test.php

в Него поместил:


define('SMARTY_DIR', '/');
require_once('/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'templates_c/';
$smarty->config_dir = 'config/';
$smarty->cache_dir = 'cache/';

$smarty->assign('name', 'Denis');

$smarty->display('/test.tpl');

Запускаю local/smarty-test.php вылазит ошибка:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file '/test.tpl'' in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('/test.tpl', NULL, NULL, NULL, true) #1 C:\open\OpenServer\domains\local\smarty-test.php(19): Smarty_Internal_TemplateBase->display('/test.tpl') #2 {main} thrown in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatebase.php on line 127

M2
На сайте с 11.01.2011
Offline
341
#1


$smarty->display('test.tpl');

не?

------------------- Крутые VPS и дедики. Качество по разумной цене ( http://cp.inferno.name/view.php?product=1212&gid=1 ) VPS25OFF - скидка 25% на первый платеж по ссылке выше
anton000
На сайте с 10.05.2013
Offline
32
#2
mark2011:

$smarty->display('test.tpl');

не?

Точно, вы гений! Этот файл же лежит вместе и с php файлом. Спасибо большое!

Не буду создавать новую тему, спрошу здесь.

В инструкции сказано что после распоковки папки libs со смарти, нужно в php.ini указать в переменной include_path каталог.

Строка у меня такая:

include_path = ".;%sprogdir%/modules/php/%phpdriver%/;%sprogdir%/modules/php/%phpdriver%/PEAR"

Я сделал так: include_path = ".;%sprogdir%/modules/php/%phpdriver%/;%sprogdir%/modules/php/%phpdriver%/PEAR;C:\open\OpenServer\domains\local"

Правильно? Если нет, то напишите пожалуйста как будет правильно?

M2
На сайте с 11.01.2011
Offline
341
#3

Вроде бы правильно.

anton000
На сайте с 10.05.2013
Offline
32
#4

Извините меня за тупость, но сейчас я решил вынести всё подключение к смарти в отдельный файл setup.php

И опять проблемы:

Warning: require(SMARTYDIRSmarty.class.php): failed to open stream: No such file or directory in C:\open\OpenServer\domains\local\setup.php on line 9

Warning: require(SMARTYDIRSmarty.class.php): failed to open stream: No such file or directory in C:\open\OpenServer\domains\local\setup.php on line 9

Fatal error: require(): Failed opening required 'SMARTYDIRSmarty.class.php' (include_path='.;C:/open/OpenServer/modules/php/PHP-5.4.13/;C:/open/OpenServer/modules/php/PHP-5.4.13/PEAR;C:\open\OpenServer\domains\local') in C:\open\OpenServer\domains\local\setup.php on line 9

smarty-test.php:


require('setup.php');

$smarty = new MySmarty;

$smarty->assign('name', 'Denis');

$smarty->display('test.tpl');

setup.php:


define('SMARTY_DIR', '/');
require(SMARTYDIR . 'Smarty.class.php');

class MySmarty extends Smarty {

function MySmarty() {
$this->Smarty();

$this->template_dir = 'templates/';
$this->compile_dir = 'templates_c/';
$this->config_dir = 'configs/';
$this->cache_dir = 'cache/';

$this->caching = true;
}
}

Что не так? Благодарю за ответ!

M2
На сайте с 11.01.2011
Offline
341
#5


define('SMARTY_DIR', '/');
require(SMARTYDIR . 'Smarty.class.php');

Константу не так написали. Нужно:


define('SMARTY_DIR', '/');
require(SMARTY_DIR . 'Smarty.class.php');
anton000
На сайте с 10.05.2013
Offline
32
#6
mark2011:

define('SMARTY_DIR', '/');
require(SMARTYDIR . 'Smarty.class.php');

Константу не так написали. Нужно:


define('SMARTY_DIR', '/');
require(SMARTY_DIR . 'Smarty.class.php');

Спасибо! Эт, не я ошибся! Это автор в учебнике ошибся)))

Сейчас вылезает вот такое: Fatal error: Uncaught exception 'SmartyException' with message 'PHP5 requires you to call __construct() instead of Smarty()' in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatebase.php:803 Stack trace: #0 C:\open\OpenServer\domains\local\setup.php(14): Smarty_Internal_TemplateBase->__call('Smarty', Array) #1 C:\open\OpenServer\domains\local\setup.php(14): MySmarty->Smarty() #2 C:\open\OpenServer\domains\local\smarty-test.php(10): MySmarty->MySmarty() #3 {main} thrown in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatebase.php on line 803

M2
На сайте с 11.01.2011
Offline
341
#7


class MySmarty extends Smarty {

function MySmarty() {
$this->Smarty();

Попробуйте вот так:


class MySmarty extends Smarty {

function MySmarty() {
$this->__construct();
anton000
На сайте с 10.05.2013
Offline
32
#8
mark2011:

class MySmarty extends Smarty {

function MySmarty() {
$this->Smarty();


Попробуйте вот так:


class MySmarty extends Smarty {

function MySmarty() {
$this->__construct();

Не помогает! Выдаёт:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "templates\test.tpl" on line 1 "Привет, {$name}!" unknown tag "private_print_expression"' in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatecompilerbase.php:665 Stack trace: #0 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatecompilerbase.php(451): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "pr...', 1) #1 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templateparser.php(2353): Smarty_Internal_TemplateCompilerBase->compileTag('private_print_e...', Array, Array) #2 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templateparser.php(3101): Smarty_Internal_Templateparser->yy_r27() #3 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templateparser.php(3201): Smarty_Internal_Templateparser->yy_reduce(27) #4 C:\open\OpenServer\domains\local\sysplugins\smarty_internal_smartytemplatecompiler. in C:\open\OpenServer\domains\local\sysplugins\smarty_internal_templatecompilerbase.php on line 665

M2
На сайте с 11.01.2011
Offline
341
#9
anton000:
unknown tag "private_print_expression"

Что-то не так делаете в шаблоне.

anton000
На сайте с 10.05.2013
Offline
32
#10
mark2011:
Что-то не так делаете в шаблоне.

Понятно! Что-то я совсем запутался в этом смарте!

Делаю самую простую вещь: файл main.conf


title = "Мой сайт"
BgColor = "Black"
BorderSize = 1

файл test.php


<html>
<head>
<title>Привет</title>
</head>
<body>
<table>
<tr>
{config_load file="config/main.conf"}
<td>Хомяк</td>
<td>{#title#}</td>
<td>Жук</td>
</tr>
</table>
</body>
</html>

И это не срабатывает! Я просто понять не могу в чём прикол? Инструкции в интернете пересмотрел нечего не выходит!

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий