Hi all,
I'm messing around with templating and I've run into a situation where I need to echo to the browser a template that contains html & php. How do I evaluate the PHP and send it to the browser?
So here's an example (main.php):
<div id = "container">
<div id="head">
<?php if ($id > 10): ?>
<H3>Greater than 10!</H3>
<?php else: ?>
<H3>Less than 10!</H3>
<?php endif ?>
</div>
</div>
And then in the template.php:
<?php
$contents; // Contains main.php in string format
echo eval($contents); // Doesn't work... How do I do this line??
?>
EDIT: My template also allows you to inject data from the controller Smarty-style. Would an output buffer allow me to do this and then evaluate my php. The ideal is that it does a first-pass through the code and evaluates all the tags in first, then runs the php. This way I can create loops and stuff from using data sent from my controller.
So maybe a more complete example:
<div id = "container">
<div id = "title">{$title}</div> <!-- This adds data sent from a controller -->
<div id="head">
<?php if ($id > 10): ?>
<H3>Greater than 10!</H3>
<?php else: ?>
<H3>Less than 10!</H3>
<?php endif ?>
</div>
</div>
Thanks!