|
Whitebeam Template Reference Documentation
|
XmlGeneric Template
execute()
Re-execute part of an XML tag tree. ADVANCED.
Syntax
XmlGeneric = rb.XmlGeneric.execute(parameters)
Parameters
The 'execute' method takes 1 parameter:
Name | Type/Value | Range/Length | Description | parameters | MetaData | | Optional. JavaScript parameters to be passed to the tagtree. These appear as global JavaScript variables to any
JavaScript executed within the tag-tree. |
Results
The 'execute' method returns structure:
Remarks The Presentation Engine
re-executes the XML sub-tree rooted at the selected branch. Invoking this method will discard the current
text output of the tag tree and rerun the entire
subtree. In the case where the tag tree simply contains static HTML - this will generate the
same text. Where the tree contains active server-side code however that code will
be re-executed using the current executing environment. So for example macro tags
defined within XmlParser that contains the tag will be executed. The tag tree re-executed may include content that executes JavaScript - either directly
through things like the <rb:script...> or <rb:eval...> tags, or indirectly
because the content includes a tag for which there is a macro tag definition - an <rb:macrotag...>.
In these situations it can be useful to pass some parameters into the tagtree. Consider the very simple
example: <rb:block rb:id="myBlock">
<tr>
<td>
<rb:eval expr="name"/>
</td>
<td>
<rb:eval expr="dataset[name]"/>
</td>
</tr>
</rb:block>
<rb:script>
var data = ["this", "is", "the", "dataset"];
var tags = rb.xml.findId("myBlock");
for var (count=0;count<data.length;count++) {
tags.execute();
rb.page.write(tags.toString());
}
</rb:script>
In this case we want to repeat the block a number of times - each time the
code generates a different table row. The example won't work because the contents
of the tagtree is always executed in the global context. To make this work you
have to pass the parameters into the execution. Re-writing the script yields the
correct behaviour: <rb:script>
var data = ["this", "is", "the", "dataset"];
var tags = rb.xml.findId("myBlock");
for var (count=0;count<data.length;count++) {
tags.execute({count:count, dataset:data});
rb.page.write(tags.toString());
}
</rb:script>
'regenerate' now has a single parameter - an object that is initialised to contain two
attributes, 'count' and 'dataset'. This object is placed at the front of the JavaScript
scope chain before executing the XML subtree. |
|
(loadtime : 87ms) |