Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create properties for a template instance inside of it's <em>created</em> event handler. And you can access the template instance as the second argument of the event map function.</p> <pre><code>Template.comment_item.created = function() { this.showChildren = false; }; Template.comment_item.events({ 'click .comment-content': function(event, template) { template.showChildren = true; } }); </code></pre> <p>HOWEVER:</p> <ol> <li>you cannot access your template instance and its properties from within a template helper.</li> <li>Your template helper needs to be given a "reactive" data source anyways for it to change on the spot.</li> <li>Even if you go through the trouble of creating your own reactive data source, your approach to this feature will <em>still</em> create X amount of variables for X amount of comments on the page. That seems like an awful lot of variables to have in memory to implement one feature.</li> </ol> <p>What I would suggest that you do instead is simplify your template to this:</p> <pre><code>&lt;template name="comment_item"&gt; &lt;li class="comment comment-displayed" id="{{_id}}"&gt; &lt;div class="comment-body"&gt; &lt;div class="comment-content"&gt; &lt;!-- changed this to a class --&gt; &lt;!-- some comment data here --&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;/template&gt; </code></pre> <p>And then programmatically add the child comments to the comment-body in your event-handler. Keep in mind the following from the Meteor documentation:</p> <blockquote> <p>A template that you declare as <code>&lt;template name="foo"&gt; ... &lt;/template&gt;</code> can be accessed as the function Template.foo, which returns a string of HTML when called.</p> </blockquote> <p>Oh, and you pass context to a template function as a JSON object. E.g.:</p> <pre><code>var context = {_id: comment_id, text: "Comment text!"}; Template.comment_item(context); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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