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.
  #46  
Old February 27th, 2006, 05:55 AM
PlaGuE PlaGuE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Edmonton Alberta Canada
Posts: 16 PlaGuE 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 PlaGuE
RE: help : looping for template

i still cant seem to fix it.hmmm.

Reply With Quote
  #47  
Old February 27th, 2006, 11:54 AM
BlackSkad BlackSkad is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 13 BlackSkad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: help : looping for template

I found another mistake, but you could have found it on your own imho. Did you take a serious effort to find the error?

You want to replace the KEY with the VALUE, so the tag will look like {blockName.key} and not like {blockName.value}.
php Code:
Original - php Code
  1. foreach ($data as $key => $value) {
  2.         $blockCode = str_replace ("{".$blockname.".".$key."}", $value, $blockCode);
  3.     }


Next time, try a little harder yourself to find the error. That will improve your php knowledge, your knowledge about this template system and it will save you a lot of time

BlackSkad

Reply With Quote
  #48  
Old February 27th, 2006, 08:49 PM
PlaGuE PlaGuE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Edmonton Alberta Canada
Posts: 16 PlaGuE 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 PlaGuE
RE: help : looping for template

thanks... yeah im still learning alot.

it still not working.

I have an idea.. i'll post back it if works.

Reply With Quote
  #49  
Old March 16th, 2006, 10:49 AM
PlaGuE PlaGuE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Edmonton Alberta Canada
Posts: 16 PlaGuE 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 PlaGuE
RE: help : looping for template

First off This piece of code was having problems.
php Code:
Original - php Code
  1.  
  2. function assign_block_vars($blockname, $data)
  3. {
  4.     $blockCode = $this->get_block($blockname);
  5.     foreach ($data as $key => $value) {
  6.         $blockCode = str_replace ("{".$blockname.".".$key."}", $value, $blockCode);
  7.     }
  8.     $this->page = str_replace ($this->return[0], $blockCode.$this->return[0], $this->page);
  9. }


keeps giving me this error:
php Code:
Original - php Code
  1.  
  2. Undefined offset: 0

on the lines where $this->return[0] is located. On BOTH the assign_block_vars and get_block functions

all have to do with the return (i think...)

This is my class
php Code:
Original - php Code
  1.  
  2. class Page {
  3.      var $page;
  4.  
  5.                // --------------
  6.                // Page($template)
  7.                // --------------
  8.                function Page($template = "templates/template.tpl")
  9.                {
  10.                     if (is_file($template))
  11.                          $this->page = implode("", file($template));
  12.                     else
  13.                          die("Template file $template not found.");
  14.                }
  15.                // --------------
  16.                // Parse($file)
  17.                // --------------
  18.                function parse($file)
  19.                {
  20.                     ob_start();
  21.                     include($file);
  22.                     $buffer = ob_get_contents();
  23.                     ob_end_clean();
  24.                     return $buffer;
  25.                }
  26.  
  27. //--------------
  28. // Replace Tags
  29. //--------------
  30.  function replace_tags($tags = array()) {
  31.     if (sizeof($tags) > 0)
  32.       foreach ($tags as $tag => $data) {
  33.         //$data = (is_file($data)) ? $this->parse($data) : $data;
  34.         $this->page = str_replace("{" . $tag . "}", $data, $this->page);
  35.         }
  36.   }
  37. //--------------
  38. // Get Block
  39. //--------------
  40.   function get_block($block){
  41.     preg_match ('#<!-- START '. $block . ' -->([^.]+)<!-- END '. $block . ' -->#',$this->page,$this->return);
  42.     $code = str_replace ('<!-- START '. $block . ' -->', "", $this->return[0]);
  43.     $code = str_replace ('<!-- END '  . $block . ' -->', "", $code);
  44.     return $code;
  45.     }
  46. //--------------
  47. // Remove Block
  48. //--------------
  49.     function removeBlock($blockName){
  50.        
  51.     // search a match for the expression
  52.     preg_match ('#<!-- START ' . $blockName . ' -->([^*]+)<!-- END ' . $blockName . ' -->#', $this->page, $resultCode);
  53.  
  54.     // replace the match with an empty string
  55.     @$this->page = str_replace($resultCode[0], '', $this->page);
  56. }
  57. //--------------
  58. // Replace Block Tags
  59. //--------------
  60. function replace_block_tags($blockname, $query) {
  61.     $this->blockcode = $this->get_block($blockname);
  62.     while ($tags = mysql_fetch_assoc($query)) {
  63.         $block = $this->blockcode;
  64.             foreach ($tags as $tag => $data) {
  65.                 //$data2 = (is_file($data)) ? $this->parse($data) : $data;
  66.                 $block = str_replace("{" . $tag . "}", $data, $block);
  67.         }
  68.       @$this->block_page .= $block ."n";
  69.         }
  70.     $this->page = str_replace($this->return[0], $this->block_page, $this->page);
  71.     unset($this->block_page);
  72. }
  73. //*
  74. //--------------
  75. // Assign Block Vars
  76. //--------------
  77. function assign_block_vars($blockname, $data)
  78. {
  79.     $blockCode = $this->get_block($blockname);
  80.     foreach ($data as $key => $value) {
  81.         $blockCode = str_replace ("{".$blockname.".".$key."}", $value, $blockCode);
  82.     }
  83.     $this->page = str_replace ($this->return[0], $blockCode.$this->return[0], $this->page);
  84. }
  85. // --------------
  86. // Output
  87. // --------------
  88. function output()
  89.  {
  90.    print $this->page;
  91.   }
  92. }


i use this code to do the replacing.
php Code:
Original - php Code
  1.  
  2. $index->assign_block_vars("Announcements",array("Content_Body"  => $row['body'],
  3.                         "Content_Header"=> $row['subject'],
  4.                         "UserName"  => $row['username']));


and in the template its something like this

php Code:
Original - php Code
  1.  
  2. <!-- START Announcements -->
  3. Title:{Announcements.Content_Header} By:{Announcements.UserName}
  4. <hr>
  5. {Announcements.Content_Body}
  6. <!-- END Announcements -->


Also im developing on windows. And I also test this on my site which is a linux host.
Both gave me errors when using
php Code:
Original - php Code
  1.  
  2. $blockCode = $this->get_block($blockname);   

and
php Code:
Original - php Code
  1.  
  2. $this->page = str_replace ($this->return[0], $blockCode.$this->return[0], $this->page);


like the above function at start/top of this post

Reply With Quote
  #50  
Old March 17th, 2006, 02:28 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help : looping for template

bump.

Reply With Quote
  #51  
Old March 25th, 2006, 07:19 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help : looping for template

Just bumping this to see if anyone has a fix for the problem posted above.

Reply With Quote