Skip to content
Snippets Groups Projects
Commit fbfec98e authored by chbaeh's avatar chbaeh
Browse files

Adds proof of concept for using helper functions in html templates

parent 7ea4ade1
No related branches found
No related tags found
No related merge requests found
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
def odsh_main_groups():
'''Return a list of the groups to be shown on the start page.'''
# Get a list of all the site's groups from CKAN, sorted by number of
# datasets.
groups = toolkit.get_action('group_list')(
data_dict={'all_fields': True})
return groups
class OdshPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.ITemplateHelpers)
# IConfigurer
......@@ -11,3 +21,9 @@ class OdshPlugin(plugins.SingletonPlugin):
toolkit.add_template_directory(config_, 'templates')
toolkit.add_public_directory(config_, 'public')
toolkit.add_resource('fanstatic', 'odsh')
def get_helpers(self):
# Template helper function names should begin with the name of the
# extension they belong to, to avoid clashing with functions from
# other extensions.
return {'odsh_main_groups': odsh_main_groups}
hier ist der footer
\ No newline at end of file
{% ckan_extends %}
{% block header_account_container_content %}
hier war der login
{% endblock %}
\ No newline at end of file
<p>The title of this site is: {{ app_globals.site_title }}.</p>
{% ckan_extends %}
{% block primary_content %}
<h3>Most popular groups</h3>
<ul>
{% for group in h.odsh_main_groups() %}
<li>{{ group.display_name }}</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment