Htmlpp

Source Code Examples

 
 Home 
 Introduction 
 Download 
 Docs 
 Support 
 Examples 
 Add-ons 
Full Sites Snippets

Using Blocks as Macros

Contributed by Enrique Bengoechea

The current implementation of macros in Htmlpp has two problems:

  • Arguments passed to the macro must be ordered and are accessed by argument number instead of names ($1, $2...). When using many arguments, it may be hard to remember the order in which arguments must be passed to the macro.
  • Symbols expansion within macros is tricky. If you define a variable within a macro and want to use it in the same macro, you must escape it as $\(variable) and it will not be expanded until next pass. This generates problems and some complex code is not even possible with macros.
IMPORTANT NOTE: These two problems will be solved in forthcoming releases of Htmlpp.

You can avoid both problems using blocks instead of macros and global variables as the means of passing arguments to the block. Of course, this requires being careful as the variables will be able to be accessed anywhere in the document, and not only in the block.

For an example of how to use this trick, have a look at the following snippet, how to make a calendar.


 
  Snippets List
Snippets List
Next Snippet
Making a Calendar
Next
iMatix
 
Copyright © 1996-99 iMatix Corporation.
Hosted by OpenAvenue.com. Made with Htmlpp. Powered by Xitami.
 
Updated: December 20, 1999
Feedback