Every template language has its own way of approaching the problem. You could, instead of writing your own template language from scratch, use one of the standard ones out there like Smarty.
If you are writing your own, you'll need at a minimum a construct that will let you express loops and conditionals. One simple approach that I've seen used before is something like:
<!-- BEGIN conditional_or_looped_block_named_foo -->
Stuff that may appear zero or more times
<!-- END conditional_or_looped_block_named_foo -->
The syntax varies widely, of course, from one language to another, but the basic approach is the same: have some markup that surrounds the portion of code you want to isolate and repeat (or omit).