How to add a menu item to CKAN's naivigation menu? -


i want make functionality of custom extension available via menu item in ckan's main navigation menu. not sure how can add new menu item extension code. appreciated.

thanks, pk

if want take advantage of ckan's main navigation menu, gets little tricky. (we had figure out. not sure if did right way, did work ckan 2.2):

first, need additional content in extension path somewhere. assuming it's @ my_extension/amazing.html, want add following my_extension/templates/header.html file (in custom extension):

{% ckan_extends %}  {% block header_site_navitagtion_tabs %}   {{ h.build_nav_main(     ('search', _('datasets')),     ('organizations_index', _('organizations')),     ('group_index', _('groups')),     ('about', _('about')),     ('amazing', _('amazing extension'))   ) }} {% endblock %} 

this cause server error, since "amazing" hasn't been registered in pylons mapped route. we'll fix next. if you've built extension properly, should have my_extension/plugins.py, you'll need add following plugin's class definition:

class amazingplugin(plugins.singletonplugin, tk.defaultdatasetform):     #or     plugins.implements(plugins.iroutes, inherit=true)     def before_map(self, m):         m.connect('amazing', #name of path route             '/amazing', #url map path             controller='ckanext.my_extension.controller:amazingcontroller', #controller             action='amazing') #controller action (method)         return m 

..where ckanext.my_extension.controller include path my_extension/controller.py, we'll create next. should consist of:

import ckan.plugins p ckan.lib.base import basecontroller  class amazingcontroller(basecontroller):     def amazing(self):         return p.toolkit.render('amazing.html') 

that's it. you've got controller mapping url nav item can call h.build_nav_main(). simple, right? ;) 1 last thing. you'll need restart apache take effect.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -