Jump to content


Template Help


5 replies to this topic

#1 Jynxis

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:The Shadows

Posted 16 September 2005 - 03:32 AM

okay i have this template class.
<?php
class Page
{
  var $page;

  function Page($tpl_file = "testy.php") {
  $template = "$tpl_file";
    if (file_exists($template))
      $this->page = join("", file($template));
    else
      die("Template file $template not found.");
  }

  function parse($file) {
    ob_start();
    include($file);
    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
  }

  function replace_tags($tags = array()) {
    if (sizeof($tags) > 0)
      foreach ($tags as $tag => $data) {
        $data = (file_exists($data)) ? $this->parse($data) : $data;
        $this->page = eregi_replace("{" . $tag . "}", $data,
                      $this->page);
        }
    else
      die("No tags designated for replacement.");
  }

  function output() {
    echo $this->page;
  }
}
?>
require_once("lib/parser.php");
$page = new Page("templates/test/index.body.php");

$page->replace_tags(array(
  "title" => "HOME",
  "added_by" => "$row[author]",
  "added_on" => "$row[date]",
"begin_cat_row" => "?????",
"end_cat_row" => "????"
));

$page->output();

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col">Title</th>
    <th scope="col"> Added on</th>
    <th scope="col">Added by</th>
  </tr>
<!--- {begin_cat_row}-->
  <tr>
    <th scope="col">{title}</th>
    <th scope="col">{added_on}</th>
    <th scope="col">{added_by}</th>
  </tr>
<!--- {end_cat_row}-->
</table>

how. would i be able to 'loop' JUST this part {{{
<!--- {begin_cat_row}-->
  <tr>
    <th scope="col">{title}</th>
    <th scope="col">{added_on}</th>
    <th scope="col">{added_by}</th>
  </tr>
<!--- {end_cat_row}-->
}}}


If anyone can find me sumtin better to use(and show me an example of wut im trying to do) plz ... for the LOVE OF GOD. tell me...lol...

Edited by PlaGuEX, 16 September 2005 - 03:35 AM.


#2 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 16 September 2005 - 07:12 AM

Put your output you wish to have in another variable.

So do a While loop and have it put all the records in the variable.

While ($var = mysql_fetch_array)){
       $output .= '<tr>
                          <td>'.$var['title'].'</td>
                       </tr>';

}
$page->replace_tags(array(
 "output" => "output",
));


#3 Jynxis

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:The Shadows

Posted 16 September 2005 - 03:01 PM

k, ima try.

#4 Jynxis

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:The Shadows

Posted 16 September 2005 - 03:34 PM

okay... um... yah... it "does" kinda work"...


but wut im trying to do ... is VISUALLY SEE TEH TEMPLATE and LOOP ONLY a CERTAIN PART.

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 16 September 2005 - 06:29 PM

Without adding to the class, or doing stuff outside of the class, no you can't. And there's no real easy way to just explain how to do something like this, simply because of the complexity, but you can see an example of the class i use Here, and hopfully decifer it, and make your own.

good luck.

#6 Jynxis

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:The Shadows

Posted 16 September 2005 - 08:28 PM

Koo thanks... ill decifer it later... right now ... i gotta worry bout ... MY Fake tooth... that just chipped(1/100 chance), while eating a jawbreaker.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users