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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 2nd, 2005, 02:47 AM
ATLien ATLien is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 ATLien User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to ATLien
PHP Template System Code

ok, I have been trying to figure this out for a while, with no luck. I used the Writing a Template System in PHP tutorial to generate a template system for my site.I am trying to implement a block system into this class.

php Code:
Original - php Code
  1. <?php
  2. class Page
  3. {
  4.   var $page;
  5.  
  6.   function Page($template = "template.html") {
  7.     if (file_exists($template))
  8.       $this->page = join("", file($template));
  9.     else
  10.       die("Template file $template not found.");
  11.   }
  12.  
  13.   function parse($file) {
  14.     ob_start();
  15.     include($file);
  16.     $buffer = ob_get_contents();
  17.     ob_end_clean();
  18.     return $buffer;
  19.   }
  20.  
  21.   function replace_tags($tags = array()) {
  22.     if (sizeof($tags) > 0)
  23.       foreach ($tags as $tag => $data) {
  24.         $data = (file_exists($data)) ? $this->parse($data) : $data;
  25.         $this->page = eregi_replace("{" . $tag . "}", $data,
  26.                       $this->page);
  27.         }
  28.     else
  29.       die("No tags designated for replacement.");
  30.   }
  31.  
  32.   function output() {
  33.     echo $this->page;
  34.   }
  35. }
  36. ?>


I want to make it so in the .tpl file, I can do this:
<!-- LOGGED_IN BEGIN -->
Code that displays only if the block is TRUE
<!-- LOGGED_IN END -->

that set that block code so it will act like below if it was not a template file.
php Code:
Original - php Code
  1. if(isset($_SESSION['loggedin']){
  2. echo "Code that displays only if the block is TRUE";
  3. }


If anyone can help me with this it would be very appreciated.

I know this was discussed in another topic, but it was not the same thing, the other topic was looking at looping stuff. But I did searchg before I posted this request.

Reply With Quote
  #2  
Old July 2nd, 2005, 03:25 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: PHP Template System Code

I would extend the class, use a regex to search for <!-- LOGGED_IN BEGIN --> and <!-- LOGGED_IN END --> and isolate the content between them, and delete it if you don't want it to show.

php Code:
Original - php Code
  1.  
  2. class newPage extends Page {
  3.  
  4.   function handleBlock() {
  5.     // $start = regex finds <!-- LOGGED_IN BEGIN --> position and return offset
  6.     // $end = regex finds <!-- LOGGED_IN STOP --> position and return offset
  7.  
  8.     if ($_SESSION[whatever-were-looking-for] != "TRUE")
  9.       // replace the data in the position between the $start and $end with ""
  10.   }
  11.  
  12. }


Hope this helps... and good luck!

-Tim

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > PHP Template System Code


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