mjallday
mjallday

Reputation: 10102

Ember.js template rendering

I'm possibly reading the docs wrong. Can someone please check out my gist and tell me why the invoices/index template is not rendering?

When I read the ember.js docs it states it should render

posts
 ↳posts/index

(invoices/index in my case). The invoices template renders however.

Handlebars:

<script type="text/x-handlebars" data-template-name="application">
    <h1>Ember Committers</h1>
    <nav>
        {{#linkTo "index"}}Index{{/linkTo}}
        {{#linkTo "about"}}About{{/linkTo}}
        {{#linkTo "invoices"}}Invoices{{/linkTo}}
    </nav>
    {{ outlet }}
</script>

<script type="text/x-handlebars" data-template-name="invoices">
    <h1>Invoices</h1>
</script>

<script type="text/x-handlebars" data-template-name="invoices/index">
    <ul>
        {{#each invoice in invoices }}
        <li>{{#linkTo "show" invoice.id}}{{ invoice.id }}{{/linkTo }}</li>
        {{/each }}
    </ul>
</script>

<script type="text/x-handlebars" data-template-name="invoices/show">
    <p>Invoice - {{ name }}</p>
</script>

<script type="text/x-handlebars" data-template-name="phone">
    <p>Contributor - {{ title }}</p>
</script>

<script type="text/x-handlebars" data-template-name="about">
    <p>About {{ title }}</p>
</script>

<script type="text/x-handlebars" data-template-name="index">
    <p>Index</p>
</script>

JavaScript:

<script type="text/javascript" defer>
    var App = Ember.Application.create({
        LOG_TRANSITIONS: true
    });
    App.ApplicationView = Ember.View.extend({
        templateName: 'application'
    });

    App.Router.map(function () {
        this.route("about");
        this.resource("invoices", { path: "/invoices" }, function () {
            this.resource("show", { path: "/:id" });
        });
    });

    var invoices = [
        {id: 1},
        {id: 2}
    ];

    App.AboutRoute = Ember.Route.extend({
        setupController: function (controller) {
            // Set the IndexController's `title`
            controller.set('title', "My App");
        }
    });

    App.InvoicesIndexController = Ember.ArrayController.extend({
        invoices: invoices
    });

</script>

Upvotes: 2

Views: 1993

Answers (1)

ahmacleod
ahmacleod

Reputation: 4310

You need to include an {{outlet}} tag in your invoices template. Since index and show are nested resources of invoices, their templates get rendered inside the outlet that you specify in the invoices template.

Take a look at the nested resources part of the Ember.js guide.

Upvotes: 4

Related Questions