Skip to content

Commit

Permalink
Add an example ITemplateHelpers extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond authored and tobes committed Feb 22, 2013
1 parent 9c48a59 commit 242ea9a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Empty file.
28 changes: 28 additions & 0 deletions ckanext/example_itemplatehelpers/plugin.py
@@ -0,0 +1,28 @@
import ckan.plugins as plugins


class ExampleITemplateHelpersPlugin(plugins.SingletonPlugin):
'''An example that shows how to use the ITemplateHelpers plugin interface.
'''
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.ITemplateHelpers)

# Update CKAN's config settings, see the IConfigurer plugin interface.
def update_config(self, config):

# Tell CKAN to use the template files in
# ckanext/example_itemplatehelpers/templates.
plugins.toolkit.add_template_directory(config, 'templates')

# Our custom template helper method.
def example_helper(self):
'''An example template helper method.'''

# Just return some example text.
return 'This is some example text.'

# Tell CKAN what custom template helper methods this plugin provides,
# see the ITemplateHelpers plugin interface.
def get_helpers(self):
return {'example_helper': self.example_helper}
6 changes: 6 additions & 0 deletions ckanext/example_itemplatehelpers/templates/home/index.html
@@ -0,0 +1,6 @@
{% ckan_extends %}

{% block secondary_content %}
{{ super() }}
{{ h.example_helper() }}
{% endblock %}
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -126,6 +126,7 @@
json_preview=ckanext.jsonpreview.plugin:JsonPreview
pdf_preview=ckanext.pdfpreview.plugin:PdfPreview
recline_preview=ckanext.reclinepreview.plugin:ReclinePreview
example_itemplatehelpers=ckanext.example_itemplatehelpers.plugin:ExampleITemplateHelpersPlugin
[ckan.system_plugins]
domain_object_mods = ckan.model.modification:DomainObjectModificationExtension
Expand Down

0 comments on commit 242ea9a

Please sign in to comment.