|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
||||||||
|
||||||||
|
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:
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:
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! |
|
#2
|
||||
|
||||
|
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)); |
|
#3
|
|||
|
|||
|
RE: Dynamic content using template tutorial
Thanks! That was what I was looking for!
|
![]() |
| Viewing: Codewalkers Forums > Other > Tutorials > Dynamic content using template tutorial |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|