Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>yield()</code> function allows you to write additional Tritium code inside the scope of a function call.</p> <p>For example, you can use the <code>wrap()</code> function like this:</p> <pre><code>wrap("div") { add_class("product") } </code></pre> <p>In this example, the <code>wrap()</code> function surrounds the current node inside a <code>&lt;div&gt;</code> tag, and then adds the class "product" to that tag, which results in the following HTML:</p> <pre><code>&lt;div class="product"&gt; &lt;!-- the node you originally selected is now wrapped inside here --&gt; &lt;/div&gt; </code></pre> <p>The function call to <code>add_class()</code> is being performed inside the <code>wrap()</code> function's <code>yield()</code> block. The <code>wrap()</code> <a href="http://tritium.io/simple-mobile/1.0.224#XMLNode.wrap%28Text%20%25tag%29" rel="nofollow">function definition</a> looks like this:</p> <pre><code>@func XMLNode.wrap(Text %tag) { %parent_node = this() insert_at(position("before"), %tag) { move(%parent_node, this(), position("top")) yield() } } </code></pre> <p>As you can see, the <code>yield()</code> call inside the function definition for <code>wrap()</code> lets the Tritium code <em>yield</em> its execution to the <code>add_class()</code> function that I wrote above.</p> <p>So to use my example again, this section of code:</p> <pre><code>wrap("div") { add_class("product") } </code></pre> <p>Is exactly like writing:</p> <pre><code>%parent_node = this() insert_at(position("before"), "div") { move(%parent_node, this(), position("top")) add_class("product") ## &lt;-- This is where the code inside a yield() block gets added } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload