This is a method of Smarty which is used to assign a value into the variable and this variable passes variable to tpl file. Assign two arguments, where first is the name with the variable name of the template file and the second is the original data.
This is the method of Smarty which is used to display and load the template .tpl file that is passed to it.
Advantages of Smarty
- Clean code presentation.
- PHP back end and front end Smarty template.
- Doesn't replace PHP but complements it.
- Fast development/deployment for the programmers and the designers
- Quick and easy to maintain.
- Syntax is easy to understand, no PHP knowledge is required.
- Flexibility for custom development.
- Security: insulation from PHP.
- Free, open source.
Syntax
Smarty syntax is used to display symbols like {$title|escape|lower}, shown below:
- include('Smarty.class.php');
- // create object
- $smarty = new Smarty;
- // assign some content. This would typically come from
- // a database or other source, but we'll use static
- // values for the purpose of this example.
- $smarty->assign('name', 'george smith');
- $smarty->assign('address', '45th & Harris');
- // display it
- $smarty->display('index.tpl')
Let's start Smarty framework. Today, I will discuss an array display into Smarty framework.
First, download Smarty folder by reference site smarty download for the latest version of Smarty.

Click source code and download Smarty framework. When downloading is complete, then downloading folder extracts and copies the Smarty folder, which is put into the xampp->htdoc folder.
First Step
To create index.php file into the Smarty folder, all folders, and the file remove the without libs folder.

Step Second
Open index.php file.
- <?php
- /**
- * Example Application
- *
- * @package Example-application
- */
- require 'libs/Smarty.class.php';
- $smarty = new Smarty;
- //$smarty->force_compile = true;
- $smarty->debugging = true;
- $smarty->caching = true;
- $smarty->cache_lifetime = 120;
- $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
- $smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
- $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
- $smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"),
- array("I", "J", "K", "L"), array("M", "N", "O", "P")));
- $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
- array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
- $smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
- $smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
- $smarty->assign("option_selected", "NE");
- $smarty->display('index.tpl');
Plugins folder: It is used for a third party code and plugin.
Templates: It is the last and final folder and it is used for all tpl files into the templates folder.




Santhakumar MunuswamyPosted Jun 25, 2016, 12:38 AM
Thank you for nice article
Prasanna MuraliPosted Jun 23, 2016, 10:19 AM
Nice one
Vignesh ManiPosted Jun 23, 2016, 8:26 AM
nice one
GokulPosted Jun 23, 2016, 3:11 AM
Thanks for sharing
kalu singh raoPosted Jun 22, 2016, 1:50 AM
Nice...
Kuppurasu NagarajPosted Jun 21, 2016, 12:38 PM
Nice Sharing..