A primer on tokens (or at least how my modules use them)


In short, a token is any text string that is replaced with something else (ie. some other text string) in later processing. For example, if you were using mailmerge software to send out letters to customers, you might use a token to represent the customer's name in the body of the letter. Then when you do the merge (or when the emails are sent), the token is replaced with the customer's name so that even though you use a single letter for every customer, each is personalized to the particular recipient.

Many of my modules use tokens to provide for much more flexibility in the designing the "look" of the displayed page. Tokens are used to represent various bits of information that may vary from product to product, category to category, order to order, etc. So a single "template" (the form that holds the tokens and sets what appears around them; ie. the template is the bit of text that determines the layouts of the tokens) can be used for many different products, for example. Each time that template is used to display a page, the tokens are replaced with the appropriate data specific to that product.
Let's assume that you want to display informatioin about a product in a very simple format:
Super Robot
Code: robot
Price: $11,000,002

Since the template will be used with many products, each with it's own name and price, you can't simply enter the product details into your template. Instead, you use tokens to represent that product data. Then as the module displays the page, it will replace the tokens with the appropriate data specific to that product. For this display you would use the template:
%prodname%
Code: %prodcode%
Price: $%prodprice%