Smarty for Beginners - File Creation
(Page 2 of 5 )
Let's go back to "smartyrules" folder. In that folder, create a new PHP file with the contents of as follows:
<?php # Filename: libs.inc.php
# the exact path is defined. $fixpath = dirname(__FILE__);
# changes this value according to your uploaded smarty distribution. # don't forget to add trailing back slash # change 'username' to your username on web hosting account define ("SMARTY_DIR", "/home/username/smarty/");
require_once (SMARTY_DIR."Smarty.class.php"); $smarty = new Smarty; $smarty->compile_dir = "$fixpath/compile"; $smarty->template_dir = "$fixpath/html"; ?> |
Save the file as libs.inc.php.
Create another new PHP file, the contents as follows:
<?php # filename: index.php require_once ("./libs.inc.php"); $smarty->display ("index.html"); ?> |
Save the file as index.php
Go to "html" directory in the "smartyrules" subfolder. Create a new html file, the contents as follows:
<html> <head> <title>My First Smarty Page</title> </head> <body> This is my First Smarty Page </body> </html> |
Save the file as index.html
All set, now you can open your browser and type your address http://www.domain.com/smartyrules. You'll see your page is generated using index.html in subfolder "html" as the template. That would your first Smarty page.
What Smarty does is compile index.html and put it in the "compile" folder then display it right away from there. You can see in the "compile" folder, there are new files, they were created by Smarty.
Next: The Basics >>
More Miscellaneous Articles
More By Hermawan Haryanto
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|