|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
LittleDen Smarty n00b
Joined: 30 Sep 2004 Posts: 1 Location: Krasnoyarsk
|
Posted: Thu Sep 30, 2004 9:01 am Post subject: Поможете новенькому? |
|
|
Никак не могу врубиться в принципы построения шаблонов и (самое главное) получения назад данных из шаблона.
Делаю простейший примерчик, цель -- вывести на странице имя/емыл после того, как эти данные ввели в поля формы. Сейчас проиллюстрирую.
Code: |
<?php
require('smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'X:/home/***.ru/www/templates/';
$smarty->compile_dir = 'X:/home/***.ru/www/templates_c/';
$smarty->config_dir = 'X:/home/***.ru/www/configs/';
$smarty->cache_dir = 'X:/home/***.ru/www/cache/';
if ($_REQUEST['registered'] == 'yes') {
$smarty->assign('name', "$smarty_get_vars('login'));
}
$smarty->display('index.tpl');
?>
|
Code: |
{if $name ne ''}Hello, {$name}!{/if}
<FORM action="{$owner}" method="POST" name="regform">
Логин: <INPUT TYPE="TEXT" name=login maxlength="15" value={$login}>
E-Mail: <INPUT TYPE="TEXT" name=email maxlength="30" value={$email}>
<INPUT TYPE="HIDDEN" name="registered" value="yes">
<INPUT TYPE="SUBMIT" name="OK" value="Ok">
</FORM>
|
Пошли вопросы.
1. Шаблон отобразится после display, но как узнать, что шаблон отображается уже повторно, после ввода данных?
2. Как всё-таки получить данные из шаблона и правильно их интерпретировать?
3. Как вообще правильно всё это делать?
Всю имеющуюся документацию перерыл, ответов не нашёл.
Извините за тупые вопросы... _________________ [Малой] |
|
Back to top |
|
toto Smarty Rookie
Joined: 28 Aug 2004 Posts: 14 Location: Russia, Tomsk
|
Posted: Thu Oct 07, 2004 10:52 pm Post subject: |
|
|
угу
документация не радует (( |
|
Back to top |
|
b166-er Smarty Rookie
Joined: 22 Oct 2004 Posts: 29 Location: Germany, Wiesbaden
|
Posted: Fri Oct 22, 2004 9:42 pm Post subject: |
|
|
privet,
k twoim worposam:
1. usnat kakoj raz twoj shablon ushe otobrasilsja s smarty nelsja (nu ili ja nesnaju ), a realizowat moshna otchen legko s php.
2. polutchjat dannije iz html w php kak obitchno. tcheres wot eti array:
$_POST, $_GET ili $_FILE
wot moj primer:
index.php:
[php]<?php
if(class_exists('Smarty')==FALSE){require_once('smarty/Smarty.class.php');}
class CustomSmarty extends Smarty {
function Smarty_Verwaltung($dir) {
$this->Smarty();
$this->template_dir = $dir.'/tmpl';
$this->compile_dir = $dir.'/cache';
//$this->compile_check = true;
$this->caching = false;
$this->debugging = false;
//$this->security = true;
}
}
$smarty = new CustomSmarty('/www/home/htdocs');
if( isset( $_POST['username'] ) && !empty( $_POST['username'] ) ){
$smarty->assign('username', $_POST['username']);
}
$smarty->display('index.tpl');
?>[/php]
/tpl/index.tpl:
Code: |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
{if !$username}<form method="post" name="test" action="index.php">{/if}
<table>
<tr>
<td>{if $username}tebja sawut: {$username}{else}<input type="text" name="username" value="">{/if}</td>
</tr>
{if !username}
<tr>
<td><input type="submit" name="send"></td>
</tr>
{/if}
</table>
{if !$username}</form>{/if}
</body>
</html>
|
poshalusta
________
Toyota Tf105 Specifications |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|