Unfortunately, this is not going to be an easy one to get a straight answer for. First off, Quark has not opened up their model through an API. This means that, while you can edit the text documents, you will find it hard to program directly into the program. If the templates are in ASCII format, you can alter them, but I am not sure it is worth doing this.
While Quark is a better DTP product (I worked in print for years), Adobe has opened up the PDF API for programming. If you were to go this route, you could potentially wrap the API calls into a simpler component that fits your need and use CFOBJECT to instantiate this object. With Microsoft, this would be ActiveX; most likely Java in the UNIX world (not implemented yet in early 4.0 CF, but perhaps in 4.5).
If the template is ASCII, and you really want to tackle this monster, you would be best to make an executable that alters the ASCII document (template) and changes lines. If you are windows, use the file system object and stream through to the portions you need to change.
If the template is not ASCII, I would say you are out of luck.
Greg