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

HTML image link from Meteor template not rendered by browser

本文关键字:链接 浏览器 图像 HTML 流星      更新时间:2023-09-26
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>

当我的应用在浏览器中运行时,将显示图像标记的 HTML,而不是图像。

例如:

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

我知道 Meteor 应用程序从/public 目录提供本地图像资产,但我不确定为什么浏览器没有渲染图像 src 标签。我能够成功显示Facebook用户名和电子邮件地址。

感谢您的帮助!

尝试将模板帮助程序更改为此内容。

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;
    }
  });
}

并像这样将这个帮助程序调用到 HTML 中。

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