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:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #61  
Old December 20th, 2006, 05:19 PM
adijux adijux is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 adijux User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: help : looping for template


Quote:
After spending ages trying to get it to work, I ended up creating my own. I was able to use the explode function to basically recognise loops, like this:

template.tpl
Code:
<table width="100%" border="0" align="center">
<tr>
<td class="thead"><b>Name</b></td>
<td class="thead"><b>Email</b></td>
<td class="thead"><b>Online?</b></td>
</tr>
<!-- BEGIN user_loop -->
<tr>
<td class="row1">{USERNAME}</td>
<td class="row2">{USEREMAIL}</td>
<td class="row1">{ONLINESTATUS}</td>
</tr>
<!-- END user_loop -->


And then the php:

php Code:
Original - php Code
  1.  
  2. $explode = explode("<!-- START member_list -->", file_get_contents("LOCATION OF TPL FILE"));
  3.  
  4. $explode2 = explode("<!-- END member_list -->", $explode[1]);
  5.  
  6. $main=$explode[0];
  7. $main=replace("{THMNAME}", $_SESSION['theme'], $main);
  8. //query here
  9. while($r=mysql_fetch_array($sql)) {
  10. $main .=$explode2[0];
  11. //here you need to do str_replace to replace the vars in the template
  12. }
  13. echo $main;


And that is a simple way of getting it to work

Yeah, this goes pretty nice, but it's a bit too simple and not so dynamical as I want to make it.
All I want to do is fix looping and make variables like that:
Code:
{Users.Id} {Users.Name} {Users.Homepage}
and so on..


I spent few weeks trying to find templating class which could include subtemplate files into main template file AND work with variables.
php Code:
Original - php Code
  1. <?php
  2. $tpl = new template('main.tpl');
  3.  
  4. $tpl->assign(array(
  5. 'text' => 'Some text goes here',
  6. 'title' => 'Problem which needs to be fixed',
  7. 'content' => 'news.tpl')
  8. );
  9.  
  10. $tpl->output();
  11. ?>

main.tpl:
Code:
<html>
<head>
<title>{title}</title>
</head>
<body>
{content}
</body>
</html>

and news.tpl:
Code:
{text}


So these variables would work and output what I need: {title} {content}, but variable {text} wouldn't output what I need (this problem was in almost all classes I tried). But this class outputs {text}.. and I can't understand why it is not working in other classes.. any ideas?

Reply With Quote
  #62  
Old April 20th, 2007, 08:23 AM
KKmaddog KKmaddog is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 63 KKmaddog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 18 m 28 sec
Reputation Power: 2
RE: help : looping for template

not sure if you still reading this but hey this topic is something im interested in so ill get it started again.

What you have to do is separate the function that inputs files and the function that replaces tags.

Heres the php code
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. class Page
  5. {
  6.   var $page;
  7.  
  8.   var $DYNAMIC = array();
  9.  
  10.   function Page($template = "index.html") {
  11.     if (file_exists("template/".$template))
  12.       $this->page = join("", file("template/".$template));
  13.     else
  14.       die("Template file $template not found.");
  15.   }
  16.  
  17.   function parse($file) {
  18.     ob_start();
  19.     include($file);
  20.     $buffer = ob_get_contents();
  21.     ob_end_clean();
  22.     return $buffer;
  23.   }
  24.  
  25.   function file_replace($file = array()) {
  26.     if (sizeof($file) > 0)
  27.       foreach ($file as $name => $loc) {
  28.         $loc = (file_exists($loc)) ? $this->parse($loc) : "";
  29.         $this->page = str_replace("{" . $name. "}", $loc,
  30.                       $this->page);
  31.       }
  32.     else
  33.       die("No file designated for inclusion.");
  34.   }
  35.  
  36.   function replace_tags($tags = array()) {
  37.     if (sizeof($tags) > 0)
  38.     {
  39.       foreach ($tags as $tag => $data)
  40.       {
  41.  
  42.         $this->page = str_replace("{" . $tag . "}", $data,
  43.                       $this->page);
  44.       }
  45.     }
  46.     else
  47.     {
  48.       die("No tags designated for replacement.");
  49.     }
  50.   }
  51.  
  52. ?>


and in the index.php file which is the template file that calls this class you put
php Code:
Original - php Code
  1.  
  2.  
  3. <?php
  4.  
  5. require_once("template_control.php");
  6.  
  7. $page = new Page();
  8.  
  9. //this has to go before replacing the tags
  10. $page->file_replace(array(
  11.   "head" => "template/header.html",
  12.   "menu" => "template/main_nav.html",
  13.   "left" => "template/sec_nav.html",
  14.   "right" => "template/content.html",
  15.   "footer" => "template/footer.html"
  16. ));
  17.  
  18. //this has to go after you include the files
  19. $page->replace_tags(array(
  20.   "TITLE" => "Testing templating system!",
  21.   "HEADER" => "Welcome to my website!",
  22.  
  23.   "FOOTER" => "the footer is copywrited on."
  24. ));
  25.  
  26. $page->output();
  27.  
  28. ?>
  29.  

Reply With Quote
  #63  
Old March 18th, 2008, 05:02 PM
Rutjes Rutjes is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 Rutjes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 42 sec
Reputation Power: 0
Question

I'm sorry for bumping up this old topic but I was wondering if someone knows how to include sub template files in the main template file by using lines like:

<!-- INCLUDE overall_header.html -->

Any help will be greatly appriciated.

Clint.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > help : looping for template


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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