0

I was trying to extend an application and found out that whenever I try to access the _id value from inside an #if clause, it always returns empty...

This example returns the {{_../id}}:

<template name="showsId">
  {{# each comments}}
    <div class="id">{{../_id}}</div>
  {{/each}}
</template>

But this one doesn't:

<template name="doesNotShowId">
  {{# each comments}}
    {{#if editingComments}}
      <div class="id">{{../_id}}</div>
    {{else}}
      <div class="id">{{../_id}}</div>
    {{/if}}
  {{/each}}
</template>

Do you know why this might be happening? As far as I know this should work as expected.

EDIT:

This is a template that's being called from another one, in this fashion:

<template name="statusitems">
  <div>
    {{#each statusItem}}
  <div>
    {{> statusComments }}
  </div>
    {{/each}}
  </div>    
</template>

That's why I'm asking for the {{../_id}}.

Keith Dawson
  • 1,475
  • 16
  • 27
  • I doubt that `{{../_id}}` will work in the current release of **Meteor** (0.7.0.1), but I would recommend switching to some experimental branch like `shark` for example. I am pretty much sure the feature you need is implemented there. – Tomasz Lenarcik Feb 13 '14 at 22:44

1 Answers1

0

For both data contexts, the comment document seems to be provided by the each iterator.

Therefore, I believe you should not be using ../ anyway since the document properties suchs as _id are already provided within the data context.

This should work as is:

<template name="doesNotShowId">
  {{# each comments}}
    {{#if editingComments}}
      <div class="id">{{_id}}</div>
    {{else}}
      <div class="id">{{_id}}</div>
    {{/if}}
  {{/each}}
</template>

So should this:

<template name="doesNotShowId">
  {{# each comments}}
    <div class="id">{{_id}}</div>
  {{/each}}
</template>
Serkan Durusoy
  • 5,447
  • 2
  • 20
  • 39
  • Probably I should have stated that these are documents inside another document, I'll edit the question accordingly. – Gastón Algaze Feb 13 '14 at 21:01
  • Hm,I should have realized that. Anyway ../_id should have been working then. Perhaps [this](http://stackoverflow.com/questions/13789622/accessing-parent-context-in-meteor-templates-and-template-helpers) and [this](http://stackoverflow.com/questions/13091914/meteor-how-to-access-parent-properties-within-nested-templates) can help. – Serkan Durusoy Feb 14 '14 at 06:50