Jump to content

Recommended Posts

How can i loop it so i can make more links?

 

(tried to remove excess code to make it easier to understand/read)

 

Ok my code looks like this

 

 <?php

include "class_template.php";

$global = new template;

$vars = array("linkname" => "Home",
"link"      => "www.home.com");

$page = $global->make_template("global");

echo $global->insert_variables($page, $vars);

?> 

 

and my global template file looks like

 

Menu


<a href="{link}">{linkname}</a>

 

and my class_template looks like this

 

 <?php

class template
{

     var $template_dir     = 'templates/';
     var $file_ext         = '.tpl';
     var $buffer;
    
     function make_template($file)
     {
         $this->buffer = file_get_contents( $this -> template_dir . $file . $this -> file_ext );
        
         return $this->buffer;
     }
    
     function insert_variables($input, $vars)
     {    
         $search = preg_match_all('/{.*?}/', $input, $matches);
                    
         for($i = 0; $i < $search; $i++)
         {
             $matches[0][$i] = str_replace(array('{', '}'), null, $matches[0][$i]);
         }    
         foreach($matches[0] as $value)
         {
             $input = str_replace('{' . $value . '}', $vars[$value], $input);
         }
        
         return $input;
     }

}

?> 

Link to comment
https://forums.phpfreaks.com/topic/56126-looping-with-template-class/
Share on other sites

Why dont you use teh template class Aviliable From here.

See it on http://zigmoyd.sourceforge.net/man/template.php#template.

Installation and Instruction It comes with great support you can directly chat with the developers of this Class anytime. and its really too easy and Small.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.