izrafel Posted December 13, 2007 Share Posted December 13, 2007 OK i have the following problem, i need a way to change the attributes of a html template (i wrote a simple template engine), without having php in the template itself,here is an exmaple of what i want to do. template.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form action="#" method="post"> <input type="text" name="text" value="{value}" /> <input type="submit" value="submit" /> </form> </body> </html> template.php (template engine) <? class Page { var $page; function Page($template = "template.html") { if (file_exists($template)) $this->page = join("", file($template)); else die("Template file $template not found."); } function replace_tags($tags = array()) { if (sizeof($tags) > 0) foreach ($tags as $tag => $data) { $data = (file_exists($data)) ? join("", file($data)) : $data; $this->page = eregi_replace("{" . $tag . "}", $data, $this->page); } else die("No tags designated for replacement."); } function output() { echo $this->page; } function parse($file) { ob_start(); include($file); $buffer = ob_get_contents(); ob_end_clean(); return $buffer; } }//end class ?> index.php (this is showing the form that needs to be edited) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <?php require_once("template.php"); @$text=$_POST['text']; $page = new Page("template.html"); $page->replace_tags(array( "value"=>$text )); $page->output(); ?> </body> </html> So far so good, now what i want to do is, when a number is entered in form i want the bgcolor of the form to become red (for example). i have another question, for example we have a menu in a template, and in that menu we have a log in link.now the problem is how to hide that link, and in the same time, show the log out link if a person is loged in. Vice versa, if the person not loged in how to show only the link for log in, and not the link for log out. I have a lot experience with php, so please don`t tell Quote: me just set a variable in the session and then if he is loged in don`t show it. i need it to work with templates.(without having php code in the template) If you need to change smth in my "template engine" or smth in the template, feel free to do so and post it here, or tell me what i should change to make it work the way i want, and i will try. thanx Quote Link to comment 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.