Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 11th, 2006, 08:58 AM
Maz Maz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Nynäshamn, Sweden
Posts: 2 Maz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 44 sec
Reputation Power: 0
Send a message via ICQ to Maz
Dynamic content using template tutorial

Hi all!

I apologize if this question already has been covered in previous posts but I couldn't seem to find it in my searches.

Anyway I'm using the Template System written by Tim. (Great work Tim! I really like the system!)

If my template.html looks like this:
Code:
<Table>
<tr><td>{header}</td></tr>
<tr><td>{main}</td></tr>
<tr><td>{footer}</td></tr>
</table>


and my index.php looks like this (simplified):
php Code:
Original - php Code
  1.  
  2.   "header" => "dat/header.dat",
  3.   "main" => "dat/main.dat",
  4.   "footer" => "dat/footer.dat"

And I wish to use the same template but replace the content linked in {main} i.e show my contact page when a contact link is submitted.
Do i link to a contact.php where there's another replace_tags() function provided pointing main to my contact.dat file? Like this:
php Code:
Original - php Code
  1.  
  2.   "header" => "dat/header.dat",
  3.   "main" => "dat/contact.dat",
  4.   "footer" => "dat/footer.dat"

I have tried this and it works but I wonder if that's a correct solution to do it? It seem that for every different page you end up with another almost similar .php file containing a similar replace_tags() function that just differs from the page that {main} points to.

Please can anyone point me in the right direction if this is the way to do it or if there's another more dynamically correct way of putting it?

Thanks in advance!

Reply With Quote
  #2  
Old November 14th, 2006, 02:28 AM
bluephoenix's Avatar
bluephoenix bluephoenix is offline
Levelheaded Curmudgeon
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Syracuse, NY
Posts: 507 bluephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 13 m 2 sec
Reputation Power: 2
Send a message via AIM to bluephoenix
RE: Dynamic content using template tutorial

Yes, that's one way to do it. Another way is to pass some sort of token in the url and then retrieve it using $_GET. So, for example, you could have mysite.com/index.php?action=post. Then depending on what the token's value is you can use a switch statement and branch the replace_tags accordingly.

<?php
$action = (isset($_GET["action"]) ? strtolower($_GET["action"]) : "";
switch ($action) {
case "post":
$header = "dat/post-header.dat";
$main = "dat/post-main.dat";
break;

case "read":
$header = "dat/read-header.dat";
$main = "dat/read-main.dat";
break;
// and so forth...
default:
$header = "dat/default-header.dat";
$main = "dat/default-main.dat";
break;
}

$template->replace_tags(array(
"header" => $header,
"main" => $main));



Reply With Quote
  #3  
Old November 14th, 2006, 07:23 AM
Maz Maz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Nynäshamn, Sweden
Posts: 2 Maz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 44 sec
Reputation Power: 0
Send a message via ICQ to Maz
RE: Dynamic content using template tutorial

Thanks! That was what I was looking for!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Dynamic content using template tutorial


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway