So we all know that you should always, not only in PHP, separate code from content/design/html. (I have seen people that say the opposite here today)
I mean, you don't want one of these in bigger projects, do you?
<?php
echo '<div id="blah"><b>'
. $username . '</b>'
. $stuff . '<more HTML mixed with PHP...>';
?>
But: What is a good approach to separate code from content?
I have been using a simple template system that replaces wildcards in templates mostly.
e.g:
<div id="blah"><b>%USERNAME%</b>%STUFF% <...>
(located in a single file)
Later you can just call a function similar to GetTemplate( 'myTemplate', array ( 'USERNAME' => 'Stranger' ) );
Finally, the questions:
- Is this a good way of separating code and content?
- How do you do that when not working with a framework?
- Is there a better way?