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 October 19th, 2004, 02:06 PM
Ceppoy Ceppoy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Ceppoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Template system

I have couple of questions about Writing a Template System in PHP tutorial. I have this template system and now I am wondering how should I get the dynamic content into it. If I have for example 50 pages I have to do a file for each page to folder dat/... page1, page2...page50.

How should I do the dynamic content and links in menu?

Reply With Quote
  #2  
Old October 20th, 2004, 01:07 AM
niko_zeta niko_zeta is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Rossmoyne, WA, Australia
Posts: 105 niko_zeta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to niko_zeta Send a message via AIM to niko_zeta Send a message via Yahoo to niko_zeta
RE: Template system

That depends on the engine you use, the syntax varies. But, in general, you have a PHP file that takes care of the programming aspect, and sends the results in the form of variables to the template, which is simple HTML with some custom tags for dynamic content. So in reality you would have two files for each page: a .php file and a .tpl (or whatever) page. Here is an example, using Smarty:

PHP file (index.php):
php Code:
Original - php Code
  1.  
  2. // load Smarty library
  3. require('Smarty.class.php');
  4.  
  5. $smarty = new Smarty;
  6.  
  7. $smarty->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';
  8. $smarty->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';
  9. $smarty->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';
  10. $smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
  11.  
  12. $smarty->assign('name','Ned');
  13.  
  14. $smarty->display('index.tpl');


Template file (index.tpl):

{* Smarty *}
<html>
<head>
</head>
<body>
<h1>Hi, {$name}</h1>
</body>
</html>
<!-- End of index.tpl -->

That's the very basic of course. Most template engines can also loop through arrays, perform basic mathematic calculations and so forth.

Reply With Quote
  #3  
Old December 16th, 2004, 02:49 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: Template system


Quote:
If I have for example 50 pages I have to do a file for each page to folder dat/... page1, page2...page50.

How should I do the dynamic content and links in menu?


If you're using the templating class from the tutorial, what I've done is pass a get variable and use that to determine which dat/file to use.

-Tim

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Template system


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 3 hosted by Hostway