简体   繁体   English

流星模板的HTML图像链接未由浏览器呈现

[英]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. 当我的应用在浏览器中运行时,将显示image标签的HTML而不是图像。

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. 我知道Meteor应用程序从/ public目录提供本地图像资产,但是我不确定为什么浏览器未呈现image src标签。 I am able to successfully display the Facebook users name and email address. 我能够成功显示Facebook用户名和电子邮件地址。

Thanks for your help! 谢谢你的帮助!

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. 并像这样将辅助函数调用到HTML中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM