2013-11-26 212 views
1

Ember Community Assemble!emberjs - 有条件地在更大的模板中呈现模板

我想有条件地在application.hbs侧边栏内使用{{render''}}小模板,但该侧边栏的内容取决于我们路由到的模型的hbs。例如,“许可”边栏的内容与“个人资料”边栏的内容不同。

现在我只能一次渲染所有的侧栏内容,而不管选择什么model.hbs。

<!-- Right Sidebar in application.hbs START --> 
    <div id="sidebar-wrapper" class="super-super-float-right-col"> 
     <div id="sidebar-wrapper" class="super-float-right-col"> 
     <div id="sidebar-wrapper" class="float-right-col"> 
      {{render 'applicant'}} <!-- only available to '/person/#' --> 
      {{render 'location'}} <!-- only available to '/permit/#' --> 
     </div> 
     </div> 
    </div> 
<!-- Right Sidebar END --> 

    <div class="The rest of the content"> 
     {{outlet}} <!--inserts the rest of the html into the main content container --> 
    </div> 

我不希望这两个“申请人”和“位置”的,因为他们都高于同时呈现,而我希望将数据“申请”的内视的编号改变'人'。同样的关系适用于“位置”的“内部permit.hbs”

VpcYeoman.PermitRoute = Ember.Route.extend({ 
    renderTemplate: function() { 
     this.render({ render:'location'}); 
    } 
}); 

Application_route.js是空白,现在

回答

2

虽然1.2.0介绍{{view}}使用属性模板名称的能力,它不适用于{{render}}

那么你的选择是使用{{view}}如果可以的话,还是在模板一系列{{#if}},或组件/查看包裹的东西来呈现(单程选择做这将是有一个模板对于每个渲染以及将templateName属性绑定到parentController属性的选择视图,以确定哪个应该显示)

Here是我用来实验的jsbin。

+0

谢谢,迈克尔! currentSidebar是否暗示我还应该添加一个currentSidebar.hbs文件以在application.hbs中呈现? –

+0

我刚刚检查过,它是1.2.0,“{{view someProperty}}”已被修复,并且它对** {{{render someProperty}}不起作用** –

+0

作为替代方案,您会有什么建议? –