diff --git a/ckanext/example_itemplatehelpers/__init__.py b/ckanext/example_itemplatehelpers/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/ckanext/example_itemplatehelpers/plugin.py b/ckanext/example_itemplatehelpers/plugin.py new file mode 100644 index 00000000000..ca072dfc9a3 --- /dev/null +++ b/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} diff --git a/ckanext/example_itemplatehelpers/templates/home/index.html b/ckanext/example_itemplatehelpers/templates/home/index.html new file mode 100644 index 00000000000..3b524a078fd --- /dev/null +++ b/ckanext/example_itemplatehelpers/templates/home/index.html @@ -0,0 +1,6 @@ +{% ckan_extends %} + +{% block secondary_content %} + {{ super() }} + {{ h.example_helper() }} +{% endblock %} diff --git a/setup.py b/setup.py index 0a7b3818510..fc9fda35371 100644 --- a/setup.py +++ b/setup.py @@ -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