Smarty Framework in PHP – Info PHP

 

Smarty function

 

Assign

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.

 

DisplayThis 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:

  1. include(‘Smarty.class.php’);  
  2.   
  3. $smarty = new Smarty;  
  4.   
  5.   
  6.   
  7. $smarty->assign(‘name’‘george smith’);  
  8. $smarty->assign(‘address’);  
  9.   
  10. $smarty->display(‘index.tpl’)  

Let’s start Smarty . 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. 

  1.  
  2.  
  3.  
  4.  
  5.   
  6.   
  7. require ‘libs/Smarty.class.php’;  
  8.   
  9. $smarty = new Smarty;  
  10.   
  11.   
  12. $smarty->debugging = true;  
  13. $smarty->caching = true;  
  14. $smarty->cache_lifetime = 120;  
  15.   
  16. $smarty->assign(“Name”“Fred Irving Johnathan Bradley Peppergill”, true);  
  17. $smarty->assign(“FirstName”array(“John”“Mary”“James”“Henry”));  
  18. $smarty->assign(“LastName”array(“Doe”“Smith”“Johnson”“Case”));  
  19. $smarty->assign(“Class”array(array(“A”“B”“C”“D”), array(“E”“F”“G”“H”),  
  20.                                array(“I”“J”“K”“L”), array(“M”“N”“O”“P”)));  
  21.   
  22. $smarty->assign(“contacts”array(array(“phone” => “1”“fax” => “2”“cell” => “3”),  
  23.                                   array(“phone” => “555-4444”“fax” => “555-3333”“cell” => “760-1234”)));  
  24.   
  25. $smarty->assign(“option_values”array(“NY”“NE”“KS”“IA”“OK”“TX”));  
  26. $smarty->assign(“option_output”array(“New York”“Nebraska”“Kansas”“Iowa”“Oklahoma”“Texas”));  
  27. $smarty->assign(“option_selected”“NE”);  
  28.   
  29. $smarty->display(‘index.tpl’);  

Now create configs folder. Its used for the database configuration.

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.

Output

Article Prepared by Ollala Corp

You might also like
Leave A Reply

Your email address will not be published.