Latest Register Log In

+ Advanced Search

Introduction to Template Variables

Introduction to Template Variables
By
09/25/03 (Edited 03/11/14)

A template variable is an item you find in a template which will not be displayed to the user looking like it does in the template. Instead, these variables are replaced with appropriate HTML at the time the page is viewed according to the particular contents of the page. Rather than writing a separate page for each category, as you would with HTML, in these templates you can use {CATNAME} and it will automatically be replaced with the appropriate category name when the visitor views it.

Template variables come in types according to what areas they are associated with. Member variables carry information about who is viewing the page. Article variables carry information about a particular article. Category variables carry info about a particular category, and comment variables about a particular comment. Naturally, these variables can only be used in areas where they make sense. A comment variable on a category page will not work, for example, since there's no way to guess which comment it is intended to be.

Whenever you add a new field to an area, it then becomes a variable for it's associate area. So the variables listed in this area of the manual may not be a complete list of variables for your individual use.

A few variables are external to this scheme and can be used anywhere... these are discussed in the 'global template variables' entry.

There are a few of special categories of template variables:
1) Booleans. When you're writing a template conditional and want to test whether something exists, add BOOL to the end of your regular template variable. If you want to check the article field fieldname, for example, use {LINKFIELDNAMEBOOL}. For another example, <IF {CATDESCRIPTIONBOOL}> will test for the existence of a category description.
2) Currency. When your field represents a currency value, displaying it as a plain number isn't always desirable. For example, instead of $2.50 it would show 2.5. You can append CURRENCY to get it formatted properly. For exmaple, if you want to display the article field price, use {LINKPRICECURRENCY}.
3) Formatted numbers. If you've set up decimal and thousands separators in the tweaks at Admin -> Settings -> Tweaks Editor or in your language pack, append FORMAT to the template variable to show the friendly formatted version (use this only for display, never in template conditoinals). For example, {MEMBERSUBMISSIONSFORMAT}.




Description Learn the basics of these markers which stand in for dynamic information.
Rating
Views 2586 views. Averaging 0 views per day.