logged_with_bugmenot Posted June 3, 2007 Share Posted June 3, 2007 I want to use a template for my website. A guy on another forum told me I had to use a template parser like Templatepower or Smarty. Isn't there an easier way, just to implent a code or something? I only want one template file and connect that one to a PHP-file with content. Then be able to change the content to content from another PHP-file when I click on a link on my site. No more functions needed. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/ Share on other sites More sharing options...
seopaul Posted June 3, 2007 Share Posted June 3, 2007 if you split your webpage in half and include the into the script files you will only have 2 files to worry about for the whole website Header.php: <html> <head> header info here. </head> <body> <div><?php Footer.php : ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267215 Share on other sites More sharing options...
logged_with_bugmenot Posted June 3, 2007 Author Share Posted June 3, 2007 Yeah, but I want to use a template.. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267221 Share on other sites More sharing options...
logged_with_bugmenot Posted June 3, 2007 Author Share Posted June 3, 2007 Can someone help me? I wanna use a .tpl file connected.... Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267259 Share on other sites More sharing options...
dough boy Posted June 3, 2007 Share Posted June 3, 2007 I don't understand the question. Use SMARTY if you want a templating engine. If you just want 1 page that dynamically includes content, then just create 1 page and use a switch statement to include whatever file(s) you want. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267262 Share on other sites More sharing options...
logged_with_bugmenot Posted June 3, 2007 Author Share Posted June 3, 2007 Can't I just implent a code to display the template on a site, then show the content of the site on a specific place on the template? Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267411 Share on other sites More sharing options...
chigley Posted June 3, 2007 Share Posted June 3, 2007 file.tpl <b>This is some random html</b> index.php <?php // Do something echo file_get_contents("file.tpl"); // Output the template // Do some other thing ?> Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267413 Share on other sites More sharing options...
logged_with_bugmenot Posted June 3, 2007 Author Share Posted June 3, 2007 But I want the content from index.php to be shown on a specific place at the template.. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267414 Share on other sites More sharing options...
logged_with_bugmenot Posted June 3, 2007 Author Share Posted June 3, 2007 I tried this but it doesn't seems to work: index.php: <?php $title = "The title"; $content = "blablabla"; include ('template/main.php'); ?> template/main.php: <html> <head> <title><?php echo $title; ?></title> </head> <body> <?php echo $content; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267424 Share on other sites More sharing options...
Lumio Posted June 3, 2007 Share Posted June 3, 2007 How should your template looks like? My templates are built like that: <html> <head> <title>{{title}}</title> </head> <body> {{content}} </body> </html> Let's say that content is in the file template.tpl Now index.php: <?php $file = ''; if (file_exists('template.tpl') === true && ($size = filesize('template.tpl')) > 0) { $fp = fopen('template.tpl', 'r'); $file = fread($fp, $size); fclose($fp); } $var_titles[0] = '{{title}}'; $var_titles[1] = '{{content}}'; $var_replace[0] = 'Test'; $var_replace[1] = 'The content of this file is near'; $file = str_replace($var_titles, $var_replace, $file); echo $file; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267425 Share on other sites More sharing options...
clarke78 Posted June 3, 2007 Share Posted June 3, 2007 I tried this but it doesn't seems to work: index.php: <?php $title = "The title"; $content = "blablabla"; include ('template/main.php'); ?> template/main.php: <html> <head> <title><?php echo $title; ?></title> </head> <body> <?php echo $content; ?> </body> </html> You had this right... you just forgot your quotation marks. So your code should look like this: index.php: <?php $title = "The title"; $content = "blablabla"; include ('template/main.php'); ?> template/main.php: <html> <head> <title><?php echo "$title"; ?></title> </head> <body> <?php echo "$content"; ?> </body> </html> Should work fine now! Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267492 Share on other sites More sharing options...
trq Posted June 3, 2007 Share Posted June 3, 2007 You had this right... you just forgot your quotation marks. Variables do not need quotes around them. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267496 Share on other sites More sharing options...
clarke78 Posted June 3, 2007 Share Posted June 3, 2007 well then it should have worked in the first place then. It's working right now for me. Quote Link to comment https://forums.phpfreaks.com/topic/54050-template/#findComment-267499 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.