Template Functions
Template Functions
By Paul
04/18/04 (Edited 01/30/14)
WSN allows you to access any function by using a template variable. The help icons in your admin panel are an example of this... the admin templates have {FUNC_HELPICON[x]} in them, instead of the full HTML of the image and link. This {FUNC_HELPICON[x]} tells WSN to run the function named 'helpicon' while supplying the paramater x to it, and display the output.
Template functions look basically like template variables, except that they all begin with {FUNC_ to indicate that they're functions and they all include [] as a spot for the arguments to be passed if there are any. When there are multiple arguments, these are separated by <,> ... note that the space on each side must be included.
Some of the useful pre-existing template functions:
{FUNC_YESNO[x]} - This will generate the <option value... content for the inside of a yes/no selector. Pass it a template variable which you know to contain either yes or no, and it will pre-select the correct one.
{FUNC_RADIO[name <,> option1,option2 <,> selected]} - This will generate radio buttons for the specified options, with the specified name, and with the specified value selected. An example of this is in your email perferences template: {FUNC_RADIO[mime <,> plain text,MIME <,> {MIME}]}
{FUNC_SHOWFIELDVALUE[type <,> number <,> field]} - This function allows you to display the value of any particular field of any item. The 'type' argument can be 'link', 'category', 'comment' or 'member'. The number argument needs to be the id number of the item you want. The field argument needs to be one of the mysql fields for that type of item. Note that this function involves a bit of overhead and should not be used excessively or it would begin to slow down your site.
{FUNC_SHOWOBJECTMETHOD[type <,> number <,> method]} - Same as SHOWFIELDVALUE, but for object methods instead of field values. If you don't understand what an object or method is, don't worry, basically it's anything you want that isn't a field. For example, to show the URL of category #5 you can use {FUNC_SHOWOBJECTMETHOD[category <,> 5 <,> url]}.
Template functions are global, they work in any template.
If you know PHP, you can add your own template functions for whatever purpose simply by placing a function in a file in your modifications directory and having it give a return value of what you'll want to have displayed in the template. Parameters separated by <,> in the template function call will be passed as parameters to the function.
By Paul
04/18/04 (Edited 01/30/14)
Template functions look basically like template variables, except that they all begin with {FUNC_ to indicate that they're functions and they all include [] as a spot for the arguments to be passed if there are any. When there are multiple arguments, these are separated by <,> ... note that the space on each side must be included.
Some of the useful pre-existing template functions:
{FUNC_YESNO[x]} - This will generate the <option value... content for the inside of a yes/no selector. Pass it a template variable which you know to contain either yes or no, and it will pre-select the correct one.
{FUNC_RADIO[name <,> option1,option2 <,> selected]} - This will generate radio buttons for the specified options, with the specified name, and with the specified value selected. An example of this is in your email perferences template: {FUNC_RADIO[mime <,> plain text,MIME <,> {MIME}]}
{FUNC_SHOWFIELDVALUE[type <,> number <,> field]} - This function allows you to display the value of any particular field of any item. The 'type' argument can be 'link', 'category', 'comment' or 'member'. The number argument needs to be the id number of the item you want. The field argument needs to be one of the mysql fields for that type of item. Note that this function involves a bit of overhead and should not be used excessively or it would begin to slow down your site.
{FUNC_SHOWOBJECTMETHOD[type <,> number <,> method]} - Same as SHOWFIELDVALUE, but for object methods instead of field values. If you don't understand what an object or method is, don't worry, basically it's anything you want that isn't a field. For example, to show the URL of category #5 you can use {FUNC_SHOWOBJECTMETHOD[category <,> 5 <,> url]}.
Template functions are global, they work in any template.
If you know PHP, you can add your own template functions for whatever purpose simply by placing a function in a file in your modifications directory and having it give a return value of what you'll want to have displayed in the template. Parameters separated by <,> in the template function call will be passed as parameters to the function.
Description | How to use functions in templates, for advanced webmasters. |
Rating | |
Views | 3315 views. Averaging 1 view per day. |