【问题标题】:HTML image link from Meteor template not rendered by browser来自 Meteor 模板的 HTML 图像链接未由浏览器呈现
【发布时间】:2015-05-28 13:46:53
【问题描述】:
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 用户名和电子邮件地址。

感谢您的帮助!

【问题讨论】:

  • 在渲染 html 块时使用 {{{ }}} 而不是 {{ }}。
  • 谢谢@MariusDarila!

标签: javascript facebook image templates meteor


【解决方案1】:

尝试将模板助手更改为此。

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="" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多