I have simple template that’s html mostly and then pulls some stuff out of SQL via PHP and I want to include this template in three different spots of another php file. What is the best way to do this? Can I include it and then print the contents?
Example of template:
Price: <?php echo $price ?>
and, for example, I have another php file that will show the template file only if the date is more than two days after a date in SQL.
The best way is to pass everything in an associative array.
To build the template:
Your template page could be something like this:
Extract is a really nifty function that can unpack an associative array into the local namespace so that you can just do stuff like
echo $title;.Edit: Added underscores to prevent name conflicts just in case you extract something containing a variable ‘$page’ or ‘$data’.