|
The Metadata Plugin Metadata Management for Manila |
Site last updated 2/24/2006; 12:33:21 PM |
|
conditionalString() macro
Sometimes you want text to appear on a web page only if a certain condition is true. You could do that with a trigger, but that requires access to the server and must be checked for every page. A solution to this problem is to use the conditionalString() macro.
Suppose we have a meta type called The keywords for this page are: apple, banana, orange. This is easily accomplished using our showVal() macro as follows: The keywords for this page are: {showVal("keywords")} However, if no keywords are defined for the page this solution will give us The keywords for this page are: But that's not what we want. If no keywords are defined, we don't want to display anything at all. Enter the conditionalString() macro. At a minimum, you must tell the conditionalString macro what string you want to display and what the conditions are. Default conditions are to display the string if the meta type you give is not blank. So for the above scenario, we'd enter {metaDataMacros.conditionalString("The keywords for this page are: {keywords}", "keywords")} Note the use of the pseudomacro {keywords} within the conditional string. The full parameters of the conditionalString macro are as follows:
s is the string you want displayed or suppressed. op is the operation you want to perform. != means 'not equal to'. testval is the value you want to test the value of metaname against. So you can see that in our example above, the computer basically says 'If the value for the keywords meta type on this page is not equal to "" then display s.' Sharp readers will be wondering whether the value of testval can be a pseudomacro too, enabling macros like the following: {metaDataMacros.conditionalString("keywords and section match", "keywords", op:"=", testval:"{section}")} This will display the string "keywords and section match" if the values of the keywords meta type and the section meta type are identical. Because this macro calls the eval() macro under the hood, the opportunity is given to set the dateFormat and expandEmailAddresses parameters that eval() uses. You can ignore these if you don't need the features they offer. And, as with many metadata macros, you can force the message context by setting the msgNum parameter to the msgNum of the page whose metadata you want used for evaluation.
|
|||||||||||||||||||
| This page last updated Wednesday, July 23, 2003 at 11:02:55 AM. | (7258) |