desithugg Posted May 21, 2007 Share Posted May 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52399-php-templates/ Share on other sites More sharing options...
trq Posted May 21, 2007 Share Posted May 21, 2007 There is no built in template engine in php, therefore you need to define the template class. You can either do this yourself (can be quite complex) or use one of the existing template engines like smarty. Quote Link to comment https://forums.phpfreaks.com/topic/52399-php-templates/#findComment-258574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.