title: javascript get value of Mongo field already rendered - Meteor
body: <p><em>Hey everyone, thank you very much for your help. Question is edited per suggestions in the comments.</em></p>
  
  <p>I'm new to Mongo and Meteor.</p>
  
  <p>I have a collection "posts" with a field "slug".</p>
  
  <p>The "post" template is populating correctly with each post's values. Slug value is always something like "my-great-post".</p>
  
  <p>I need to get the text value for the _id's slug, which will be different each time the template is accessed, encode it, write a string, and spit the string back out into the template. </p>
  
  <p><strong>Things tried</strong></p>
  
  <ul>
  <li><p>can't return a value for "this.slug" or "this.data.slug" in either template helpers or onRendered, even though collection is defined and correctly populating spacebars values in the template</p></li>
  <li><p>"this" returns "[object Object]" to console.log</p></li>
  <li><p>app crashes when I try to javascript encode and deliver a string from the helper, probably I don't fully understand helper syntax from the documentation</p></li>
  </ul>
  
  <p><em>(I followed advice in the comments to avoid trying to create scripts in the template html, so below is more information requested by everyone helping on this thread)</em></p>
  
  <p><strong>- Template html -</strong></p>
  
  <pre><code>{{#with post}}
  
  &lt;div class="blog-article"&gt;
    &lt;div class="blog-header"&gt;
      &lt;div class="left"&gt;
  
        &lt;!-- title --&gt;
        &lt;h1 class="post-title"&gt;{{title}}&lt;/h1&gt;
  
        &lt;div class="holder"&gt;
          &lt;div class="post-tags"&gt;
            &lt;!-- tags --&gt;
             {{#each tags}}
                &lt;span&gt;{{this}}&lt;/span&gt;
             {{/each}}
          &lt;/div&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;
  
    &lt;/div&gt; 
  
    &lt;div class="blog-post"&gt;
      &lt;div class="blog-copy"&gt;
  
        &lt;!-- date --&gt;
        &lt;div class="post-date"&gt;{{post_date}}&lt;/div&gt;
  
        &lt;!-- social --&gt;  
        &lt;div class="blog-social"&gt;
           &lt;!-- 
                 &lt;a class="so-facebook" target="_blank" href="need to encode slug here"&gt;&lt;/a&gt;
           --&gt;       
         &lt;/div&gt;
  
         &lt;!-- ============== post ============== --&gt;
  
         {{{content}}}
  
         &lt;!-- ============ end post ============ --&gt;
  
       &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  {{/with}}
  </code></pre>
  
  <p><strong>- Template js -</strong></p>
  
  <pre><code>Template.post.onCreated(function() {
    var self = this;
    self.autorun(function() {
      var postSlug = FlowRouter.getParam('postSlug');
      self.subscribe('singlePost', postSlug);  
    });
  });
  
  Template.post.helpers({
  
    post: function() {
      var postSlug = FlowRouter.getParam('postSlug');
      var post = Posts.findOne({slug: postSlug}) || {};
      return post;
    } 
  
     // can't get these working in a helper, out of helper they crash the app 
     // console.log(this.slug);   
     // console.log(this.data.slug);
  
  });
  
  Template.post.onRendered( function () {
  
     // these do not work 
     // console.log(this.slug);   
     // console.log(this.data.slug);
  
  }); 
  </code></pre>
  
  <p><strong>db.posts.findOne();</strong></p>
  
  <pre><code>{
    "_id" : ObjectId("576c95708056bea3bc25a91f"),
    "title" : "How Meteor Raised the Bar For New Rapid-Development Technologies",
    "post_date" : "May 28, 2016",
    "image" : "meteor-raised-the-bar.png",
    "slug" : "how-meteor-raised-the-bar",
    "bitlink" : "ufw-29Z9h7s",
    "tags" : [
      "Tools",
      "Technologies"
             ],
    "excerpt" : "sizzling excerpt",
    "content" : "bunch of post content html"
  }
  </code></pre>
  
  <p>If some one can solve this using any method, I will accept answer with joy and gratitude most intense.</p>