简体   繁体   English

灰烬,在动态模板中呈现内容

[英]Ember, rendering content in a dynamic template

I'm running into a bit of a brick wall with how to render content inside some dynamic HTML content which I don't control, with Ember v1.13.1. 对于Ember v1.13.1,如何在一些我无法控制的动态HTML内容内呈现内容,我遇到了一些麻烦。 In this particular scenario, I'm getting a navigation head, and navigation foot from a service call and putting them in my component: 在这种特定情况下,我将从服务调用中获得导航头和导航脚,并将它们放入我的组件中:

export default Ember.Component.extend({
  // I don't control these. They come from somewhere else
  bodyStart: '<div class="header">...</div><div class="contentBody">',
  bodyEnd: '</div><footer>...</footer>',
});

So, in my component template, I'm trying to do something like: 因此,在组件模板中,我正在尝试执行以下操作:

{{{bodyStart}}}
{{yield}}
{{{bodyEnd}}}

I would expect the yield content to be placed inside a <div class="contentBody"> element, but it's not. 我希望将yield内容放置在<div class="contentBody">元素内,但事实并非如此。 Instead content body is closed before the {{yield}} , and the bodyEnd closing div is ignored. 而是在{{yield}}之前关闭内容主体,并忽略bodyEnd关闭div。

It's possible I'm just missing something obvious. 我可能会遗漏一些明显的东西。 Any ideas on how to solve this would be greatly appreciated. 任何有关如何解决此问题的想法将不胜感激。

Cheers 干杯

I believe what happens is that each {{{variable}}} is constructed independently and independently inserted into the DOM, which leads to unclosed DOM nodes that gets closed. 我相信发生的事情是每个{{{variable}}}都是独立构造的,并且独立地插入DOM中,这导致未封闭的DOM节点被封闭。 The only way I can think of is to include the template compiler and recompile the template with bodyStart and bodyStop. 我能想到的唯一方法是包括模板编译器,然后使用bodyStart和bodyStop重新编译模板。

App.ContentWrappedComponent = Ember.Component.extend({
  startBody: '',
  endBody: '',
  layout: function(){
    return Ember.HTMLBars.compile(
      this.get('bodyStart') + 
      '{{yield}}' + 
      this.get('bodyEnd')
    );
  }.property('bodyStart', 'bodyEnd')
});

You also need to add to your Brocfile.js: 您还需要添加到Brocfile.js:

app.import('bower_components/ember/ember-template-compiler.js');

JSBin: http://emberjs.jsbin.com/ticituxapa/3/edit?html,css,js,output JSBin: http ://emberjs.jsbin.com/ticituxapa/3/edit?html,css,js,output

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

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