Trouble understanding template concepts (not engine specific)

I am in the process of creating my first web app and I am at a point where I have some basic CRUD functionality. I got tired of looking at the default browser styling so I decided to use Twitter Bootstrap (TBS) to implement some basic styling. Once I started adding all the extra divs and classes required to implement TBS, I realized that this would be a real pain if I had to do this for every page in my site. I figured some sort of templating was the answer. I have never used a template engine but I think I have a very basic understanding of templating outside the scope of any particular templating engine. The two basic methods of templating that I think I understand are: 1) Using variables in the template; or 2) Using the find and replace method (which I believe Smarty uses if I’m not mistaken). However, all of the examples I’ve seen show a very basic HTML template with some very simple variable or search/replace methods. In my code though it doesn’t seem that simple. For instance, my page may start out with all of the TBS divs and other tags, followed by some PHP code to show query results, followed by more tags to close the TBS divs. Then I may have more PHP code followed by more HTML. In the variable replacement method of templating that I’ve seen, they simply replace a variable with some echoed text. But it’s not that easy when your PHP code is more complex.

[code]<?php include_once "includes/header.php" ?>

<?php include_once "includes/beginning_scripts.php" ?>

PHP CODE HERE

</div><!--class="span3"-->
<div class="span3">
</div><!--class="span3"-->

PHP CODE HERE

</div><!--class="span8"-->
<div class="span2">
</div><!--class="span2"-->
[/code]

if you want to stop repeating code just create the html/php that you want to use on multiple pages and save it as a html or php document then when you want to use it just call the file back using
[php]<?php include 'head.php'; ?>[/php]
. hope this helps and i havnt missed the point

That was my original thought, but my problem is with the HTML code that is between the two sets of PHP code.

[code]PHP CODE HERE

</div><!--class="span3"-->
<div class="span3">
</div><!--class="span3"-->

PHP CODE HERE[/code]

It’s the closing tags of the section above the first PHP and rest of the HTML after the second PHP. Now, in this example, I could create another file to include for the rest of the HTML code. But, this “middle” code will not always be consistent from page to page. So, I’d end up having to repeat myself anyway if I ever needed to change that HTML.

Sponsor our Newsletter | Privacy Policy | Terms of Service