chronister Posted January 21, 2008 Share Posted January 21, 2008 Hello, I am creating a mass mail system for my company. I want to have templates available for different types of mail. I am wondering how to set it up so that what the sender types in the textarea gets placed in the template file properly. I did this as a test $testvar = 'Inserted Test Var'; $template = file_get_contents(TEMPLATE_DIR.'template1.php'); // I have $testvar inside this template file echo $template; I get nothing or I get $testvar depending if I have the php tags below Here is template1.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?=$testvar ?> <!-- This gives me nothing--> $testvar <!-- this gives me $testvar --> </body> </html> How can I make it so I can take the $_POST data from a form, and set the template code into a var having it replace a var inside the template file with the data from the form I hope that makes sense to ya's. Nate Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/ Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Try it with a Global variable instead. Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445245 Share on other sites More sharing options...
chronister Posted January 21, 2008 Author Share Posted January 21, 2008 Did not work. I tried a global var and session vars. The variable is not being replaced properly. I did something like this before, but I cannot remember what how the hell I did it. Nate Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445266 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Short tags are turned on? Also, of course $testvar would give you $testvar in HTML. HTML can't parse a php variable outside of php. Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445269 Share on other sites More sharing options...
chronister Posted January 21, 2008 Author Share Posted January 21, 2008 Solved it... I found the script I used before to do this type of thing <?php $testvar = 'Inserted Test Var'; include(TEMPLATE_DIR.'shipping_pizza.php'); echo $body; ?> Here is where it all happens at. <?php ob_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?=$testvar ?> <!-- Gotta have it in PHP tags. ?> </body> </html> <?php $body = ob_get_contents(); /* this is where it happens... this takes the contents of ob_start and puts it inside a var. */ ob_end_clean(); /* clears the buffer without displaying it */ ?> Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445276 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Probably should still use <?php instead of <?, just in case you move to a server where short tags are disabled. Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445282 Share on other sites More sharing options...
chronister Posted January 21, 2008 Author Share Posted January 21, 2008 I don't use short tags.... e.g <? vs <?php I used the shorthand echo statement <?=$var ?> I do believe there is a difference between the 2. One is laziness and the other is a build in shorthand statement. Nate Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445334 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 <?= is a <? shortag. Disable short tags and watch it stop working. I don't use short tags.... e.g <? vs <?php I used the shorthand echo statement <?=$var ?> I do believe there is a difference between the 2. One is laziness and the other is a build in shorthand statement. Nate Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445337 Share on other sites More sharing options...
chronister Posted January 21, 2008 Author Share Posted January 21, 2008 Ahhhhhh... a little research and I find your correct.. I did not realize that <?= fell into the same category as <? I thought the = sign made it different for some reason. Makes sense though. Nate Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445359 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Yeah, = is just short for echo. Link to comment https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/#findComment-445366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.