2.6. Tags

Most of the template logic is built of OPT tags. They work and sometimes also look like XML/XHTML, however there are some important differences which will be pointed here. By default, the tags are also enclosed inside curly brackets: { and }. The programmer may define new delimiters, which may be used by the template designer. Here we can see a simple pair of tags:

Example 2.19. Simple tags

static text
{tag}
static text enclosed in the tags
{/tag}
static text

The ending tag starts with / and next there is a name of closed tag. Like in XML, you have to remember to close the tags in the reversed order they were opened. The example below is invalid and it will cause a syntax error:

Example 2.20. Invalid tags

{tag1}
{tag2}
{/tag1}
{/tag2}

If OPT does not know, how to process some tag, it ignores it and all the content located inside. This is because some other tags may make use of it, so it is better not to display them like a static text. The next consequence of this behavior is that the mistakes in the tag names are not reported by the template compiler! So, if something does not display, but should do this, check the name of the tag.

Since 1.1.0, OPT supports namespaces known from XML. If the namespace is not provided, OPT assigns the tag to the default one: opt. Thus, the tags sometag and opt:sometag mean exactly the same. Separate OPT extensions may use different namespaces, for example Open Power Forms uses opf to idenfity its tags.

OPT allows to use single tags, as well:

Example 2.21. Single tags

{singletag/}

There is also another type that does not appear in XML: alternative tags.

Example 2.22. Alternative tags

static text
{tag}
static text enclosed in the tags
{tagelse}
alternative content of the tag
{/tag}
static text

The tags may take one or more parameters. OPT provides here two different syntaxes:

  1. Position-based syntax: {tag=parameter1; parameter2; parameter3} - it begins with an equality character right after the tag name. The parameters are not named, we only specify the values and separate them with a semicolon. If we want to pass the default value for one of the parameters, we write !x, for example: {tag=parameter1; !x; parameter3}
  2. XML-style syntax: {tag parameter1="value" parameter2="value" parameter="3"}

The syntaxes above unsually can be freely mixed. For example, for the first time you may write {section=foo} and later in the same template - {section name="foo"}. Some of the instructions use also their own parameter format.

The parameters may be of different types. For example, if the tag requires a string, you can write {tag=this is a text}. But if there is a need to write an expression, you have to write {tag="this is a text"} or {tag parameter="`this is a text`"} (with two quotes. The first one is for the parameter parser, the second - for the expression parser).

Be careful when using OPT delimiter characters inside parameters. The code {tag="foo {bar}"} will cause error. If you think such situations may happen, ask your programmer for enable the entities directive in the configuration. Then you may use entities, known from HTML:

Table 2.2. OPT entities

OPT entities
EntityCharacter
&&
""
''
&lt;<
&gt;>
&lb;{
&rb;}

Two last entities may be used also in a static template code outside OPT tags and expressions.