I have a site I’m working on that needs to have multiple secondary navigations based on roles. Each page could have multiple roles (think tags). I have been able to get the nav built, but only if I include one role. Adding additional roles and it breaks.
YAML:
---
title : 'Color'
roles : Marketing
content-type :
updated : 'September 15, 2013'
link : 'color'
---
Helper:
helpers do
def pages_by_role(role)
sitemap.resources.select do |resource|
resource.data.roles == role
end.sort_by { |resource| resource.data.title }
end
end
```
Navigation output (using Slim):
ul
- pages_by_role(‘Marketing’).each do |p|
li
a href="#{ p.data.link }" #{p.data.title}
Produces:
```
As soon as I add an additional role (roles: Marketing, UX), this breaks. What I want is to produce the navigation based on what is included in in the YAML, not an exact string match. I’ve tried modifying the YAML various ways, nesting nodes, arrays, quoting each role, but all fail.
Help? I know the blog engine can do this easily with tags, but I’d have to do heavy refactoring of the structure make it work with the given IA this site needs. I thought it would be easier to make my own helper, but I guess I’m too new to Ruby to figure this out.