Jump to content

Recommended Posts

Umm, I'm trying to learn how to make templates, and am using a lil code I found on the net to try and see  how it works but I have an error

the html template

//tmpl.txt
Hello My name Is %name. I am %age %sex From %country.
My array Element 1 is %tmpl_arrr[0]
My array Element 2 is %tmpl_arrr[1]
My array Element 3 is %tmpl_arrr[2]
My array Element 4 is %tmpl_arrr[3]
My array Element 5 is %tmpl_arrr[4]

The php code

<?php
//tmpl.php
//Using template Class
$tmpl = new template("tmpl.txt");//Specify The Template File
$tmpl->set("%name", "Neel");//"%var_name", "Value"
$tmpl->set("age", 18);//It Will think that You forgot to enter The % sign and do the Same Job Of %age
$tmpl->set("%sex", "male");
$tmpl->set("country", "India");
echo $tmpl->count("%tmpl_arrr");//Same as count()
echo "\n";
$tmpl->set("%tmpl_arrr[0]", "Hello");//Set The Value Indivisually
for($i=1;$i<$tmpl->count("%tmpl_arrr");$i++)
    {
        $tmpl->set("%tmpl_arrr[$i]", "My Value $i");//Set the Value in A Loop
    }
echo $tmpl->done();//returns The Changed Contents Of the File as String
?> 

and here's the error I'm getting

Fatal error: Cannot instantiate non-existent class: template in /home/pcaworld/public_html/ds/tmpl.php on line 3

Link to comment
https://forums.phpfreaks.com/topic/52399-php-templates/
Share on other sites

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.