Yes I do know that 🙂

I still need help replacing the text in one file with the other looping file 🙁

    i edited it. is that what your talking about?

      I never thought about loading the news template first. Anyway that seems to be what I need but I'm getting an error 🙁

      Fatal error: Call to a member function get_contents() on a non-object in C:\Program Files\Apache Group\Apache2\htdocs\news\index.php on line 94

      line 94 is ...
      $replacement = $news_template->get_contents();

      Can I get some help with this too please?

        does the variable $news_template exist?

        you need to have
        $news_template = new template();
        before trying to use it.

          Your right I needed to make $news_template = new template();

          But this dosn't give me the results I wanted. The suggested code above outputs the news.tpl file with the replacements and then the main.tpl file after it with the replacements. I need the replacements to be made to both files and then have the text in main.tpl be raplaced with news.tpl(with the replacements)

            Originally posted by NateDawg


            I need the replacements to be made to both files and then have the text in main.tpl be raplaced with news.tpl(with the replacements)

            thats exactly what the example i provided does.

            take a closer look at what i posted.

            it sounds like your doing this

            $replacement = $news_template->publish(); 
            

            instead of what i showed you to do

            $replacement = $news_template->get_contents(); 
            

            this is the exact reason i said to add the get_contents() method

            if you still cant figure it out, post your code.

              OK this is the template class

              I renamed get_contents() to contents()

              I worked with the code a bit and now the templates are replacing each other ok but instead of showing all of the results from my news query it only shows the last result.

              class template {
              
                 private $template;
                 function load($filepath) {
                    $this->template = file_get_contents($filepath);
                    $this->template = ereg_replace("<!-- START COMMENTS -->(.*\s*)<!-- END COMMENTS -->", "",
                    $this->template);
                 }
              
              
                 function contents() {
                  return $this->template;
              	}
              
                 function replace($var, $content) {
                    $this->template = str_ireplace("<#$var#>", $content, $this->template);
                 }
              
                 function publish() {
                    echo $this->template;
                    }
              }

              Here is the code in the while loop

              $template = new template;
              
              $template->load("template/news_tpl.html");
              
              $template->replace("member_name", "$member_name");
              
              $template->replace("website", "$member_website");
              

              And this is the final code that calls the main template and echos the output.

              $main_template = new template();
              $main_template->load("template/main_tpl.html");
              $replacement = $template->contents();
              $main_template->replace("CONTENT", $replacement);
              
              $main_template->publish();

                I still need some help getting the news template to loop 🙁

                  
                  
                  
                  $main_template = new template();
                  $main_template->load("template/main_tpl.html"); 
                  
                  
                  loop () {
                  
                  $template = new template;
                  $template->load("template/news_tpl.html");
                  
                  $template->replace("member_name", "$member_name");
                  
                  $template->replace("website", "$member_website");
                  
                  // now we add the result to our main template so it doesnt get lost on the next loop iteration
                  $main_template->replace($some_var, $template->contents());
                  
                  
                  }
                  
                  
                  

                    OK I finally found a solution! Thanks for all you help rehfeld.

                    //At the top....
                    
                    $main_template = new template();
                    $main_template->load("template/main_tpl.html");
                    
                    
                    //The code in the loop
                    
                    while{
                    
                    $template = new template;
                    	$template->load("template/news_tpl.html");
                    	$template->replace("member_name", "$member_name");
                    	$template->replace("website", "$member_website");
                    
                    //THIS PART IS THE KEY
                    $replacement .= $template->contents();
                    
                    }
                    
                    //And at the end publish it 
                    
                    $main_template->replace("CONTENT", "$replacement");
                    $main_template->publish();
                    
                    
                      Write a Reply...