Referring to macro instances

Release 1.0 - ...

SXML provides the concept of scope, so you can refer to instances of macros using Viper methods.

The syntax for referring to macro instances is:

  • page
    Always refers to the ROOT SXML element, thus the enclosing element in the RenderTemplate Body SXML.
  • page.<id>
    Refers to the SXML element with Id set to <id>.
    Note that each Id used in SXML elements must be unique throughout page rendering and the life-cycle of macros.
  • this
    Refers to the current macro, that is the macro directly above the statement in the SXML hierarchy.
  • this.parent[.parent[...]]
    Moves up in the hierarchy to the macro specified.
  • scope.<id> (1.02)
    Refers to the SXML element in the same buffer scope having localid set to <id>. This reduces SXML complexity, is less error-prone and easier to maintain because no global scope is used.

Examples

Smartsite SXML CopyCode image Copy Code
{page.setforcedresult($buf)} <!-- force the page result to be the content of the buffer -->
{page.myplaceholder.clear()} <!-- clear the placeholder with Id 'myplaceholder' -->
{string.trim(this.result())} <!-- trim the macro result (in ResultFormat parameter) -->
{this.parent.field(title)}   <!-- refer to the formatting macro from within a nested se:if macro in a rowformat parameter -->
{scope.fmt.field(title)}     <!-- refer to the formatting macro having localid set to 'fmt' -->