Results 1 to 10 of 10

Thread: Template Class:::Help ME

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Template Class:::Help ME

    okay i have this template class.
    PHP Code:
    <?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;
      }
    }
    ?>
    PHP Code:
    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(); 
    PHP Code:
    <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
    PHP Code:
    <!--- {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}--> 
    This would save a hell of a lot of time .... n skinning and in coding.

    Tho if anyone found a better example for this... plz tell me.
    Last edited by PlaGuE; Sep 16th, 2005 at 04:11 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width