|
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 |
Marcinnn Smarty n00b
Joined: 01 Oct 2007 Posts: 0
|
Posted: Mon Oct 01, 2007 9:50 pm Post subject: Pocz?tki w smarty |
|
|
Hej! Przepisuje na ?ywca przyk?ad z wikipedii
Przyk?ad [edytuj]
Plik szablonu Smarty mo?e wygl?da? nast?puj?co:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
<html>
<head>
<title>{$tytul}</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body> {* To jest komentarz, NIE b?dzie widoczny w wynikowym pliku HTML *}
<p>{$tresc}</p>
</body><!-- To jest komentarz, który B?DZIE widoczny w wynikowym pliku HTML -->
</html>
Taki plik szablonu mo?na wykorzysta?, tworz?c plik PHP:
define('SMARTY_DIR', 'smarty-2.6.9/' );
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates/compile/';
$smarty->cache_dir = './templates/cache/';
$smarty->caching = false;
$smarty->error_reporting = E_ALL;
$smarty->assign('tytul', 'TYTU?: To jest prosty przyk?ad wykorzystania Smarty ...');
$smarty->assign('tresc', 'TRE??: To jest wiadomo??, ustawiona funkcj? assign()');
$smarty->display('index.tpl');
Tworze dany plik php i plik tpl mam w tym samym katalogu pliki zalecane Smarty.class.php
Smarty_Compiler.class.php
Config_File.class.php
debug.tpl
i ?ci?gni?te katalogi
/internals/*.php
/plugins/*.php
i mi to wszystko nie dzia?a. Czytam rózne instrukcje itd., i nie bardzo wiem o co chodzi. Kto? móg?by mi co? doradzi?? |
|
Back to top |
|
V3rit4S Smarty n00b
Joined: 18 Nov 2007 Posts: 0 Location: Poland
|
Posted: Sun Nov 18, 2007 11:50 pm Post subject: |
|
|
Najprostszy przyk?ad jak to ma dzia?a?.
utwórz sobie 4 katalogi:
- configs
- cache
- templates
- templates_c
Dla templates_c ustaw CHMOD na 777
Skopiuj z paczki któr? ?ci?gn??e? ze strony katalog libs.
Utwórz plik: smarty_setup.php
Code: | <?php
define('SMARTY_DIR', './libs/');
require(SMARTY_DIR . 'Smarty.class.php');
class Smarty_test extends Smarty {
function Smarty_test()
{
$this->Smarty();
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';
$this->caching = false;
$this->assign('app_name', 'testing');
}
}
$smarty = new Smarty_test;
?> |
Teraz utwórz jaki? pliczek (np. test.php)
a w nim: Code: |
<?php
require("smarty_setup.php");
//funkcje jakie sobie tam chcesz
$smarty->assign("test_var", "Sprawdzamy funkcje assign");
$var = "foo";
$smarty->assign("test_var2", $var);
$smarty->display("test.tpl");
?>
|
W katalogu templates utwórz plik: test.tpl
Code: |
{*smarty*}
Tutaj bedzie zawartosc 1 zmiennej: {$test_var}<br/>
Tutaj bedzie zawartosc 2 zmiennej: {$test_var2}
|
Je?li wszystko zrobisz poprawnie to powinno dzia?a? |
|
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
|