【问题标题】:Ember.js insert content into a named blockEmber.js 将内容插入命名块
【发布时间】:2014-05-09 07:36:21
【问题描述】:

是否可以使用 Ember.js/Handlebars 将内容插入到命名块中?

Rails 提供了一个 content_for 方法,它完全符合我的要求:http://guides.rubyonrails.org/layouts_and_rendering.html#using-the-content-for-method

应用程序把手模板如下所示:

{{#if isSignedIn}}
  <header>
    [ ... ]
    The content inside the header is different from page to page.
    The client wants buttons inside the header, that each have different actions.
  </header>
{{/if}}
<section id="outer-content-container">
  {{outlet}}
</section>

使用 Ember.js/Handlebars 完成此任务的最佳方法是什么?

【问题讨论】:

    标签: ember.js handlebars.js


    【解决方案1】:

    命名商店对我来说最有意义。

    假设在应用程序模板中你有一个额外的出口

    {{outlet dynostuff}}
    
    {{outlet}}
    

    然后在每条路线中你要显示不同的信息

    App.PostRoute = App.Route.extend({
      renderTemplate: function() {
        this.render(); // render the default stuff
    
        this.render('favoritePost', {   // the template to render
          into: 'application',                // the template to render into
          outlet: 'dynostuff',              // the name of the outlet in that template
          controller: 'blogPost'        // the controller to use for the template
        });
      }
    });
    

    http://emberjs.com/guides/routing/rendering-a-template/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-15
      • 2012-08-22
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      相关资源
      最近更新 更多