|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
QES Smarty Rookie
Joined: 26 May 2006 Posts: 7
|
Posted: Wed May 31, 2006 10:21 pm Post subject: Another Form of Smarty Navigation |
|
|
After trying long and hard I finally hit the solution by putting all the pieces together. Ok Here Goes:
Assume you have two pages:
index (also known as Home Page)
aboutus (Info page)
Also you have something like:
Header File
Footer File
Menu File (Navigator your site)
Then a basic file where you can keep your includes and some global defines:
base_includes (This simplifies adding some global variables instead of changeing every page)
THE CONNTECTOR FILE:
main (puts the header, menu/body, footer all together simply and clean)
----------------------------------------------------
Heres is the code:
index.php (note is a php as all of your pages will be...no more .htm(l))
[php:1:d55ad4e042]<?php
// The address here is on your acutal webserver NOT something like www.yoursite.com/files/....
include('/home/yoursite/html/qs/includes/base_includes.php');
$smarty->assign('contents', $smarty->fetch('index.tpl'));
$smarty->display('main.tpl');
?>[/php:1:d55ad4e042]
Then your about page...
aboutus.php
[php:1:d55ad4e042]<?php
// The address here is on your acutal webserver NOT something like www.yoursite.com/files/....
include('/home/yoursite/html/qs/includes/base_includes.php');
$smarty->assign('contents', $smarty->fetch('aboutus.tpl')); // Notice this is the only change is done here, nowhere else.
$smarty->display('main.tpl');
?>
[/php:1:d55ad4e042]
You have your defined header and footer file be it a picture or copyright or contact info whatever. Just name them as follows:
header.tpl (These go in the template folder of smarty; look below for more info)
footer.tpl (Must GO in the template folder)
Then your menu
menu.tpl (Notice its a .tpl so it must go into the template folder; all .tpls do) Code: | <a href="aboutus.php"><img style="border: 0px solid ; width: 205px; height: 22px;" alt="" src="images/buttons/b_aboutus.gif"></a> |
Notice that the menu is very simple. Nothing special needed. I personally keep mine in a table and thats it.
Now finally your global includes that is referenced in all of your pages.
base_includes.php (Note that it is also a PHP file)
[php:1:d55ad4e042]<?php
define('SMARTY_DIR', '/home/yoursite/html/qs/smarty/libs/'); // Notice I define the dir smarty in the beginning because later on I might change my dirs/server.
// put full path to Smarty.class.php
require(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'sm_index/templates'; // This where you define your infamous templates folder!
$smarty->compile_dir = 'sm_index/templates_c'; // Template Cache folder dont really need to touch it
$smarty->cache_dir = 'sm_index/cache'; // Cache
$smarty->config_dir = 'sm_index/configs'; // For more advanced stuff you need configs. For now forget them
?>
[/php:1:d55ad4e042]
The final File is the most important because it connects your stuff how you want it.
main.tpl (One last time stress the importance of placing .tpl files in the template folder!)
Code: | {include file="header.tpl" title='Smarty ROCKS!'}
<table style="text-align: left; width: 100%;" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<td style="vertical-align: top; text-align: left; width: 230px;"><br><br>{include file="menu.tpl"}</td>
<td style="vertical-align: top; text-align: left;">{$contents}</td>
</tbody>
</table>
{include file="footer.tpl"} |
WOW! Your done! Put it all up and test it out!........
Whoa you get an error! Cant find the index.tpl!!!!!
Solution:
Now simply define/create your index.tpl and aboutus.tpl and so on and so forth. They can be simple HTML to something more dandy. I suggest using a simple html to keep everything in line and it makes a little sense. Beware however bloated tables!
DONT FORGET TO PUT THE index.tpl and about.tpl IN THE TEMPLATE FOLDER! |
|
Back to top |
|
QES Smarty Rookie
Joined: 26 May 2006 Posts: 7
|
Posted: Wed May 31, 2006 10:23 pm Post subject: |
|
|
Sorry its so long and perhaps not the best practice/dirty but it gets a job done. My two cents to the Smarty project for helping me out. Works for me.
Thanks,
QES |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|