meteormeteor-blazespacebars

How can I do something like this in a template?: {{userScores.{{currentUserId}}.[0].score}}


This is working for me, but it is hard coded: {{userScores.KxXJYDLvCvjk9nLwo.[0].score}}

I want to use Meteor.userId() in place of the hard coded id.

How can I do that?

Of course, this doesn't work; {{userScores.Meteor.userId().[0].score}}


Solution

  • You can't do it directly in Blaze, you'll need a helper, ex:

    {{score0}}
    

    js:

    Template.myTemplate.helpers({
      score0() {
        return this.userScores[Meteor.userId()][0].score;
      }
    });