Ember template chaining

2019-08-05 04:29发布

I have this HTML/Handlebars code, what I would like is for the "outlet fav" to render the template with id "fav" and its corresponding outlet/templates-chain with expected "index". Kinda like displaying a different Ember URL as a part of the index. Is it possible natively(Without supplementing an iframe, which I think is a bad idea)? would it be considered a good practice(I know using views might help but just wondering if it is ok to walk this road)?

<script type="text/x-handlebars" id="application">
    Here we have our application
    {{outlet}}
</script>

<script type="text/x-handlebars" id="index">
    Application's First Child
    {{outlet}}
</script>

<script type="text/x-handlebars" id="index/index">
    Your Favourites
    {{outlet fav}}
</script>

<script type="text/x-handlebars" id="fav">
    {{#link-to 'fav'}}All{{/link-to}}       <!-- Link A-->
    {{#link-to 'fav.top'}}Top{{/link-to}}   <!-- Link B-->

    <!-- Expected Output from "fav/index" -->
    {{outlet}}
</script>

<script type="text/x-handlebars" id="fav/index">
     All Favourites Content
</script>

<script type="text/x-handlebars" id="fav/top">
    Top Favourites Content
</script>

<script type="text/x-handlebars" id="football">
    Football Content
</script>

JS Code: Here's what I tried

App.Router.map(function(){
    this.resource('index', {path: '/'}, function(){
        this.resource('fav', function(){
            this.route('top');
            this.route('last');
        });
    });
    this.route('football');
});
App.IndexIndexRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render();
        this.render("fav", {into: 'index'});
    }
});
Output:
===================================
Here we have our application
Application's First Child
Your Favourites
Link A
Link B
===================================

Omits the child outlet which should display content from "fav/index"

Help Appreciated.

1条回答
Animai°情兽
2楼-- · 2019-08-05 04:41

You can add an additional render call in IndexIndexRoute,

App.IndexIndexRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render();
        this.render("fav", {into: 'index'});
        this.render("fav/index", {into: 'fav'});
    }
});

http://jsfiddle.net/7b8HT/

Also, you may certainly use views as well to achieve similar results.

查看更多
登录 后发表回答