Ember 2.1.0 render partial if index page else another partial

时间:2015-10-31 00:14:01

标签: ember.js ember-cli

In my templates/application.hbs I would like to be able to set a condition to check if it is my index page I render a navigation for it, else it would render another set of navigation for in-app pages. The same for my footer. What is the best way to check this? Also, whether a user is login or not doesn't matter. My research has lead to outdated code or convention. I'm also completely new to Ember so any help would be very much appreciated. Here is my emblem attempt, but not working: if eq currentRouteName="index" = partial 'partialName' else = partial 'partialName2' Second attempt works: First run: ember install ember-truth-helpers Add this to my application template: if (eq currentRouteName "index") = partial 'partialName' else = partial 'partialName2'

1 个答案:

答案 0 :(得分:1)

应用程序控制器具有属性currentRouteName。您可以根据其值选择要渲染的导航。

application.hbs

{{#if (eq currentRouteName "index")}}
  render navigation for your index page
{{else}}
  render navigation for other pages
{{/if}}

eq助手来自ember-truth-helpers