TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How to install smarty (http://www.talkphp.com/absolute-beginners/1199-how-install-smarty.html)

Haris 09-21-2007 07:04 PM

How to install smarty
 
Smarty is a known template engine. It has expanded library of functions to help you remove your template from the code .

To use Smarty as a standalone tool and avoid installing it server-side. Follow the steps below:
  1. Download the latest stable Smarty release http://smarty.php.net/download.php
  2. Create templates_c, templates and configs folder in your PHP project root directory
  3. Copy all the files and folders from the libs folder which came with Smarty package
  4. Paste the files and folders to the root directory of your PHP project where templates, templates_c and configs folder resides.
  5. Voila, you're done!

Now to test if Smarty is working.

First, create index.php and save it with the code below:

PHP Code:

<?php

// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->assign('name','fish boy!');

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

?>

Then, create index.tpl in the templates folder:

HTML Code:

<html>
<body>
 Hello, {$name}!
</body>
</html>

If it renders Hello fish boy then Smarty is successfully connected. :)

Tanax 09-21-2007 07:45 PM

Awesome :D

However I would like to learn how to create an own template engine/class, similar to the smarty one. Do you know how to achieve it? Any tutorial/article? Perhaps you can make a tutorial about it?

Haris 09-22-2007 01:20 AM

I had a quick look to smarty and found it excellent but after reading reviews, it has come to my attention that Smarty cons are more heavier than its pros.

1. You have to learn a new language called Smarty. (Different syntax than PHP).
2. It's a language therefore it has a complier, the compiler slows down the scripts.

PHP is a templating engine itself. If you want a simple templating class(like me) then use www.phpsavant.com v2 (for now until v3 has a documentation).

It is 100% faster and easier than Smarty.


All times are GMT. The time now is 09:29 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0