Reputation:
I have an webpage written using php but now need to convert them to smarty template engine. I am rookie to smarty template engine.I find it difficult of smarty.net document.Is there any book or site from where i can learn smarty. I need a small snippet for insert function.
Upvotes: 0
Views: 598
Reputation: 1043
I think the smarty.net documentation is the very best point to start using Smarty Template Engine.
Most tutorials are based on the documentation I think.
For a very quick start you just have to require the Smarty base class:
// Require base class
require_once('Smarty.class.php');
// create new Smarty instance
$smarty = new Smarty();
// define Smarty directories
$smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir = '/web/www.example.com/guestbook/cache/';
// define a template variable, which will be shown in your template
$smarty->assign('greeting', 'Hello World!');
// force your php script to show your template file
$smarty->display('template.html');
Thats everything you need in your PHP file.
In the default configuration of Smarty you can show your template variable greeting by using
My greeting message: {$greeting}
If you open your PHP File via a browser you will see: My greeting message: Hello World!
For further information you really should read the official Smarty documentation!
Upvotes: 1