Captain Caveman
Captain Caveman

Reputation: 1536

HTML image link from Meteor template not rendered by browser

if (Meteor.isClient) {
Template.app.helpers({
'showAvatar' : function () {
  var userId = Meteor.user().services.facebook.id;
  var userAvatar = "<img src='http://graph.facebook.com/" + userId + "/picture?type=square&height=160&width=160'/>";
      return userAvatar;
    }
  });
}

<div class="container">
{{#if currentUser}}
    {{> app}}
{{/if}}
</div>
</body>

<template name="app">
    {{ showAvatar }}
</template>

When my app runs in the browser, the HTML for the image tag is displayed rather than the image.

Example:

img src='http://graph.facebook.com/123456789654/picturetype=square&height=160&width=160'/>

I know Meteor apps serve local image assets from a /public directory, but I'm not sure why the image src tag isn't being rendered by the browser. I am able to successfully display the Facebook users name and email address.

Thanks for your help!

Upvotes: 0

Views: 1110

Answers (1)

Ethaan
Ethaan

Reputation: 11376

Try changing the Template helper to this.

if (Meteor.isClient) {
Template.app.helpers({
showAvatar : function () {
  var userId = Meteor.user().services.facebook.id;
  var userAvatar = 'http://graph.facebook.com/' + id + '/picture?type=square&height=160&width=160';
      return userAvatar;
    }
  });
}

And call this helper into the HTML like this.

<img src="{{showAvatar}}" alt="" />

Upvotes: 2

Related Questions