![]() |
| > Home > Documentation > Latest documentation > Interchange tag introduction |
|
Interchange tag introductionIntroductionInterchange tags use a style similar to HTML, but with "[square brackets]" replacing "<chevrons>". Interchange tags are also similar to HTML in syntax, in that they accept parameters and that there are both standalone and container tags. The parameters that can be passed are similar too (i.e. parameter="value"). Parameter syntaxSummary
When using the [tagname] syntax, there must be no whitespace between the left bracket ("[") and the tag name. Most tags can accept some positional parameters. This makes parsing faster and, in most cases, is simpler to write. The following is an example tag call:
This tag causes Interchange to look in the user's form values hash and return the value of the "city" form parameter, which might have been set with the following:
Positional parameters cannot be derived from other Interchange tags. For example, the following will not work:
If the named parameter syntax is used then parameters can contain other tags. For example, the following will work:
There are exceptions to the above rule when using list tags, such as [item-list], [loop], [query] and others. These tags, and their exceptions, are explained on their corresponding pages. Tags and parameter names are not case sensitive, so [VALUE NAME=something] and [value name=something] will be treated exactly the same. The Interchange development convention is to type Interchange tags and parameters in lower case. This makes pages and tags easier to read. Some tags, such as [control-set] include a hyphen (-) in their name. In these cases, an underscore (_) may be used if you prefer (i.e. [control_set]). The two forms are interchangeable, except that an ending tag must match the tag (i.e. don't use [control-set]...[/control_set]). Having said that, hyphens look better and are preferred (by me).
Container tagsHow the result of the tag is displayed depends upon whether it's a container or a standalone tag. A standalone tag has no ending element. For instance:
A container tag has a closing tag (for example, "[tagname] ... [/tagname]"). The following code will insert the user's name, providing they have given it to you in a form. A container tag has both a beginning and an ending element, as shown in the following example:
A container tag will have its output re-parsed for more Interchange tags by default. To inhibit this behaviour, set the reparse to 0. It has been found, however, that the default reparsing is almost always desirable. The output of a standalone tag will not be re-interpreted for Interchange tags (with some exceptions, such as [include filename]. Most container tags will not have their contents interpolated (parsed for Interchange tags) before being passed the container text. Exceptions include [calc], [currency] and [seti]. All container tags accept the interpolate=1 tag parameter which if set true, causes the interpretation to take place. If the default is for a particular tag to interpolate its body text then passing an interpolate=0 parameter will inhibit this. HTML-style commentsYou are also allowed to use "<!--[" and "]-->" as interchangeable alternatives to plain square brackets, so [tagname] and <!--[tagname]--> are equivalent. This allows you make your raw tags appear as comments to HTML browsers or editors. You might want to do this if your editor has trouble with Interchange tags, when editing Interchange page templates. To properly HTML-comment contained body text, place your comment-style brackets appropriately, for example:
Note that you must include whitespace between the HTML comment delimiters and the square brackets if you wish to actually comment out tag output in the browser. For example, if [value name] expands to "Kevin":
To prevent Interchange tags from being interpolated at all, you can either set the no_html_comment_embed pragma, or enclose the block in a special [comment] container. For example:
becomes:
Besides not being interpolated, [comment] blocks do not appear in the final output text sent to the client, so you can be completely safe regarding any unintentional code or information leakage. If you are modifying the special administrative interface pages and intend to use this syntax then see the Interchange tag parsing order section, below. Named vs. positional parametersThere are two styles of supplying parameters to a tag: named and positional. In the named style you supply a parameter name=value pair just as most HTML tags use:
The positional-style tag that accomplishes the same thing looks like this:
The parameter name is the first positional parameter for the [value] tag. Some people find positional usage simpler for common tags, and Interchange interprets them somewhat faster. If you wish to avoid ambiguity you can always use named parameters. In most cases, tag parameters specified in the positional fashion work the same as named parameters. However, there are a few situations where you need to use named parameters:
Interpolating parametersIf you want to use the value of a tag within a parameter of another tag, you cannot use a positional call. You should also quote the parameter containing the tag you want to have expanded. For example, this will not work:
To get the [scratch somevar] to be interpolated, and its result passed to the [area] tag, the parameter must be named and quoted, as follows:
The "href" parameter's value (scan) did not need to be quoted. The "arg" parameter only needed to be quoted because its value contained whitespace. Without the quotes, the whitespace would be taken to be a delimiter between individual parameters, which is the main reason why the uncorrected example would have failed to produce the desired result.
Parameter quotingSingle and double quotesSingle (') and double quotes (") both have the same effect, and can be mixed to avoid confusion in the parser. For example:
Vertical bars (pipes)Vertical bars (|), also known as pipes, can also be used as quoting characters, but have the unique behaviour of stripping leading and trailing whitespace. For example:
could be better expressed as:
Back-ticksBack-ticks (`) should be used with extreme caution since they cause the parameter contents to be evaluated as Perl code, using the equivalent of a call to the [calc] tag. For example:
is the same as:
Omitting quotes altogetherExactly when can you omit the quotes around parameter values? The first answer is trivial: Never omit the quotes and you'll never run into trouble. The other answer says "omitting quotes earns you a bonus for style and achieves small parser speed improvement." However, if the value contains whitespace then you must quote it. To quote values, you can use double quotes ("), single quotes (') or vertical bars (|). Vertical bars have the additional functionality of removing leading and trailing whitespace, but generally you can use all types in combination to do three levels of quoting with Interchange tags. For more deeply nested constructs, use direct Perl code. The above answers to the quoting problem, however, are still not all there is to know about quoting. In general, loop sub-tags do not need quotes (even though they sometimes contain whitespace) because they are parsed in a separate pass, before the general parser gets to work. Here's an example that would work properly with quotes omitted. Pay attention to [item-field uri] which, at first sight, looks like it is invalid because it is not quoted and contains a space.
[area [value mypage]] would not work because the [value] tag shown is not a loop sub-tag. You might wonder why unquoted tags are even allowed. The answer is performance; If you have large lists of tags you can achieve significant speed-ups by using positional parameters. Parsing and disassembling named parameters takes more CPU cycles to process. Attribute arrays and hashesIntroductionSome tags allow you to pass an array or hash as the value of a parameter. For an ordinary tag, the syntax is as follows:
Here is an example of an attribute array, where "0" and "1" are array index values:
The [area] tag, for example, treats a search specification array as a joined search, automatically adding the other relevant search fields, including the "co=yes to indicate a combined search. Coordinated and joined searches are described in the Interchange search engine documentation.
Perl callsBefore passing attributes to a tag, the Interchange tag parser would convert the above example to an anonymous array reference. It would use the resulting arrayref as the value for the "search" attribute in this example. If you were passing the above example directly to a tag routine within a [perl] block, or a UserTag, you must actually pass an anonymous array as the value of the attribute, as follows:
Similarly to use a hash reference for the 'entry' attribute:
Interchange tag parsing orderStandard parsingUnder normal circumstances, the template page containing tags and HTML is parsed in the following order:
Nonstandard parsing within the admin interfaceParsing of content via the specialised [regenerate] usertag, included with the administrative interface, does not obey the above order. The MV_AUTOLOAD and "<!--[tagname]-->" escapes are skipped. There are some other more subtle differences as well. In the very unlikely event that you need to check this in the source code, compare the interpolate_html() and cache_html() subroutines in Interpolate.pm. Nonstandard parsing of sub-tagsSub-tags are parsed within the containing array-list or hash-list context created by the containing tag. See the Looping tags and sub-tags category.
Array list contextIn array-list context, sub-tags are processed in the following order:
Hash list contextIn hash-list context, sub-tags are processed in the following order:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home | Legal nonsense | Privacy policy | Contact us |