Introduction to Template Variables
Introduction to Template Variables
By Paul
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 forum, as you would with HTML, in these templates you can use {CATNAME} and it will automatically be replaced with the appropriate forum 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. Topic variables carry information about a particular topic. Forum variables carry info about a particular forum, and post variables about a particular post. Naturally, these variables can only be used in areas where they make sense. A post variable on a forum page will not work, for example, since there's no way to guess which post 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 forums 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 topic field fieldname, for example, use {LINKFIELDNAMEBOOL}. For another example, <IF {CATDESCRIPTIONBOOL}> will test for the existence of a forum 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 topic 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}.
By Paul
09/25/03 (Edited 03/11/14)
Template variables come in types according to what areas they are associated with. Member variables carry information about who is viewing the page. Topic variables carry information about a particular topic. Forum variables carry info about a particular forum, and post variables about a particular post. Naturally, these variables can only be used in areas where they make sense. A post variable on a forum page will not work, for example, since there's no way to guess which post 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 forums 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 topic field fieldname, for example, use {LINKFIELDNAMEBOOL}. For another example, <IF {CATDESCRIPTIONBOOL}> will test for the existence of a forum 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 topic 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. |