I read some postings about creating hash keys in jQuery.

How to create a hashed email in jQuery?

So I did this in my meteor to get the Gravatar profile photo from github email address. But it is not working. I think Hash Key is produced correctly but I am not sure how to do this in Meteor.

Following is my trying. in HTML file

      <template name="messages">
         {{#each messages}}
       <strong>{{name}}</strong> : {{message}}<br>
         {{/each}}
         <img src=img_add/>
      </template>

in Javascript file

 var hash = CryptoJS.MD5(git_email);
 var img_add = "http://www.gravatar.com/avatar/" + hash;

This produces a broken link.

How do I insert profile Gravatar photo in meteor, given email address?

有帮助吗?

解决方案

You need to use a helper just like in the hello world example.

Your client side javascript:

Template.messages.img_add = function() {
    var hash = CryptoJS.MD5(git_email);
    return img_add = "http://www.gravatar.com/avatar/" + hash;
}

Your template:

 <img src={{img_add}}/>

Or if you want to use it in the {{#each }} loop, use this slight modification & make sure your {{img_add}} helper is within the {{#each }} block. I'm not too sure how your doing the variables, but as long as the git_email is in each of your documents you're looping over.

Template.messages.img_add = function() {
    var hash = CryptoJS.MD5(this.git_email);
    return img_add = "http://www.gravatar.com/avatar/" + hash;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top