This is a fairly simple script to write providing you store your template information in a DB and index them or alternately an indexed flatfile (with a db being the better option unless you need to use a flatfile).
If you provide a bit more details I could do this for you, but you will need to provide quite a bit more with regards to specific information. If you wish, send me a PM.