Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Submitting another answer b/c I'd like to keep my previous one just for the records. I think this approach will work better though. </p> <p>Inside your html, you're going to define two sections. The first is where you're going to place your template code. It will go inside a comment inside a plain div tag. The second is where the template will be placed for Knockout to consume. It looks like this:</p> <pre><code>&lt;template name="koTemplate"&gt; &lt;div id="myTemplate"&gt; &lt;span&gt;Here is my template &lt;a href="#"&gt;with children&lt;/a&gt;&lt;/span&gt; &lt;/div&gt; &lt;script type="text/html" id="test"&gt;&lt;/script&gt; &lt;/template&gt; </code></pre> <p>Then in your client JS code, you're going to add <a href="http://docs.meteor.com/#template_rendered" rel="nofollow">a callback to run when the template is rendered</a> </p> <pre><code>Template.koTemplate.rendered = function () { // Get the first node, then get the content inside of it var templateHtml = this.firstNode.innerHTML; // Remove the element so it doesn't get rendered this.firstNode.parentNode.removeChild(this.firstNode); // another option is to surround the contents inside the template w/comments, but that loses syntax highlighting // Get the target node for placing the template in var templateNode = this.lastNode; // place the content from the original node to the target node templateNode.innerHTML = templateHtml; }; </code></pre> <p>This will basically get the content of the template, remove the template, then place it inside the script tags. The result will look like: </p> <pre><code>&lt;script type="text/html" id="test"&gt; &lt;span&gt;Here is my template &lt;a href="#"&gt;with children&lt;/a&gt;&lt;/span&gt; &lt;/script&gt; </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