Reputation: 3065
I want to be able to only display a sidebar on some of my routes. How can I achieve something like this:
<div class="container">
<div id="ember-app">
<script type="text/x-handlebars">
// if currentRoute == /something, then show this:
<div class="row">
{{partial sidebar}}
<div class="span9 offset3 user-feed">
{{outlet}}
</div>
</div>
// else, show this:
{{outlet}}
// endif
</script>
</div>
</div>
<script type="text/x-handlebars" data-template-name="_sidebar">
// Sidebar code here ...
</script>
So when I visit /#/something I should see the sidebar, but on all other routes, I shouldn't.
Upvotes: 2
Views: 1541
Reputation: 1165
A simple fix may be to use the partials argument with quotes?
{{partial 'sidebar'}}
Upvotes: 1
Reputation: 3872
You can observe the currentPath property to match the current route with Regex.
App.ApplicationController = Ember.Controller.extend({
showSidebar: function(){
var routes_array = ['two','four'],
currentPath = this.get('currentPath'),
filteredArray, showSideBar = false;
routes_array.forEach(function(itm){
var tab = new RegExp('^'+itm+'*');
if(!Em.isEmpty(currentPath.match(tab)))
showSideBar = true;
});
return showSideBar;
}.property('currentPath')
});
Upvotes: 3