Skip to content

Commit

Permalink
example_itemplatehelpers use a function not a method
Browse files Browse the repository at this point in the history
It's not a good idea for template helper functions to be class methods,
because self is not thread-safe.
  • Loading branch information
Sean Hammond authored and tobes committed Feb 22, 2013
1 parent 33e9672 commit 7bca148
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ckanext/example_itemplatehelpers/plugin.py
@@ -1,5 +1,11 @@
import ckan.plugins as plugins

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

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

class ExampleITemplateHelpersPlugin(plugins.SingletonPlugin):
'''An example that shows how to use the ITemplateHelpers plugin interface.
Expand All @@ -15,14 +21,7 @@ def update_config(self, config):
# 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,
# Tell CKAN what custom template helper functions this plugin provides,
# see the ITemplateHelpers plugin interface.
def get_helpers(self):
return {'example_helper': self.example_helper}
return {'example_helper': example_helper}

0 comments on commit 7bca148

Please sign in to comment.