codeplant/simple-navigation

Add custom html inside

jordanlance opened this issue · 1 comments

I would like to add custom html inside my links, for a bootstrap badge count.
Would it be possible to add an :badge => User.count option to the rendering?
I have looked at overwriting the rendered but could not find out exactly how to approach this.
Could the authors perhaps be so kind to provide an simple example on how to add your own custom render params?

My goal is to do something like this:

 primary.item :users, "Users", admin_users_path,
                :badge => User.count,
                 :highlights_on => lambda { ["admin/users"].member?(params[:controller]) }

Or is there an existing method that can facilitate this? Kind regards

andi commented
  1. Create your own renderer (you can extend the SimpleNavigation::Renderer::List renderer)
  2. load your own renderer in navigation.rb (navigation.renderer = MyRenderer)
  3. specify your badge parameter as html-option in your navigation config:
    primary.item :key, 'Nav1', path, html: {badge: X}
  4. Do whatever you need to do with the badge count in the renderer. See existing List renderer on how to access the html params...