Smarty Library Tutorial: first example for beginner

Smarty is a template engine for PHP. It help you to separate application logic and content from its presentation.

In this article you will experience a small example application.

First of all you need to download and install the library smarty from the official page of the project.

Create a file named index.php and write in this code:



// create new smarty object

$smarty = new Smarty;

// assign content

$smarty->assign('title', 'This is my article');

$smarty->assign('content', 'Hello word!');

// display the template



Create a file named template_index.tpl and write in this code:


Title: {$title}
Content: {$content}


Finally, visit the index.php page...

Related articles