mike parr's pages
Web pages with a macro processorIncluding code in a web page with a macro processorThis article shows you how to insert standard text in a web page (or any text file).Here is why you might want to do this. Here are two imaginary pages from a company website: +----------------------------------------------+ | | | ABC and Co | | PRODUCTS | | | +----------------------------------------------+ | | ... rest of page, with product info here | | +----------------------------------------------+and +----------------------------------------------+ | | | ABC and Co | | SALES | | | +----------------------------------------------+ | | ... rest of page, with sales info here | | +----------------------------------------------+I've not bothered to do the above in Html - instead I've roughed-out the pages. The main thing is that - like most websites - every page has a standard heading. This often deals with beginning some table definitions, perhaps a logo etc. Obviously, we don't wish to duplicate identical text in each file, because it makes it hard to apply consistent changes. But look at the above two pages - the headings are not identical - one says SALES, the other PRODUCTS. In fact these could equally be an image of a warehouse, and an image of a banknote. So - we have a standard heading ,with minor variations dependent on which page the heading prefixes. You can use a program known as a macro-processor to do the insertion of standard text, and it can also use parameters, to allow for small variations. Don't get confused between a macro- processor and a keystroke recorder. We are talking about files of text here, not keystroke commands.
Which macro-processor?There are several. Unix has one known as m4, and you can probably get a port of this for MS Windows. The drawback of m4 is that (like most macro-processors) is uses a range of special characters, and often, these characters exist in Html text. You can program round this, but - because I had the code for a simple macro-processor along m4 lines, I decided to write my own (named macro), by adapting existing code. The resulting program is nowhere near as powerful as m4, but is more suitable for Html files.Using MacroWe create a file containing 'definitions'. Each definition has a name -which we choose - and a body, and some optional 'parameters'. In this example, we will create a file named defs.txt, with two definitions, which we name header and trailer (you can choose the names). Here is the file defs.txt:
define <html> <title>ABC and Co - param1 </title> <center> <h1>ABC and Co <p> param1 </h1> </center> |