Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js - default template to render into an outlet?

Tags:

ember.js

So I have a page which looks like the following

[ Nav Bar ]

|         |
| Content |
|         |

The nav bar I want to be constant across all pages. So the approach I used was to set my page up as follows:

[ Nav Bar ]

{{outlet}}

This is great, I can now render different pages into my outlet for different routes.

But what if I want a default template to be rendered into the outlet for my home page?

I've managed to achieve this by redirecting / to /home, but there must be a better way to do this which allows me to render a default home page at / without re-routing?

Any advice appreciated,

Thanks, Daniel

like image 811
bluepnume Avatar asked Aug 04 '13 18:08

bluepnume


2 Answers

To render stuff in the {{outlet}} at the root page /, you have to define a handlerbar script for index:

Your navbar code probably look like this:

<script type="text/x-handlebars">
  <div class="navbar ...">
    ...
  </div>

  {{outlet}}
</script>

The root page that will be place inside {{outlet}} is the fallowing:

<script type="text/x-handlebars" id="index">
    <div class="container">
      <h1>Root page!!</h1>
    </div>
</script>

In other words, you have to create a handlebar script that will have an id="index".

Should work. It doesn't need any js code to work.

like image 118
darkzangel Avatar answered Nov 10 '22 04:11

darkzangel


I must admit this property is not well documented and buried in the docs for Ember.View but you could try setting the defaultTemplate property on your ApplicationView. See here for more info on that (search in the page for 'defaultTemplate').

Hope it helps.

like image 1
intuitivepixel Avatar answered Nov 10 '22 04:11

intuitivepixel