Evaluate

On this page:

Syntax

<txp:evaluate />

The evaluate tag can be used as either a single or container tag. When used as a single tag, it will evaluate the expression given by the query attribute and output its value. When used as a container tag, it will first check whether the query expression (if set) produces an empty result and output nothing in this case. Otherwise, it will process the contained tags optionally filtered by the test attribute. If all of them produce empty results, nothing will be output. Otherwise, it will return the whole processed content.

Attributes

Tag will accept the following attributes (case-sensitive):

query="expression"
A numerical, logical or string XPath expression to evaluate.
Values: 2 * 2, string-length("Textpattern") < 10, and so on.
Default: unset.
test="tags list"
The (top-level) tags to test for non-emptiness.
Default: unset (test all tags).

Examples

Example 1: Increase the value of a variable

<txp:variable name="counter" value="0" />

<txp:article>
    <txp:variable name="counter" value='<txp:evaluate query=''<txp:variable name="counter" /> + 1'' />' />
    ...
</txp:article>

Other tags used: article, variable.

<txp:evaluate test="linklist">
    <section>
        <h4>Links</h4>
        <txp:linklist wraptag="ul" break="li" />
    </section>
<txp:else />
    <p>No links registered yet.</p>
</txp:evaluate>

Other tags used: else, linklist.

Genealogy

Version 4.7.0

Tag support added.

See something wrong in this document? Outdated info, a broken link, faulty code example, or whatever? Please write an issue and we’ll fix it.