Skip to content

Commit

Permalink
[#523] Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Apr 25, 2013
1 parent 554dc91 commit 98ad884
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/extensions.rst
Expand Up @@ -75,6 +75,32 @@ stable, backward-compatible and with clear deprecation guidelines as
development of CKAN core progresses. This interface is available in
:doc:`toolkit`.


Example Extension
-----------------

::
# Example Extension
# This extension adds a new template helper function `hello_world` when
# enabled templates can `{{ h.hello_world() }}` to add this html snippet.

import ckan.plugins as p

class HelloWorldPlugin(p.SingletonPlugin):

p.implements(p.ITemplateHelpers)

@staticmethod
def hello_world():
# This is our simple helper function.
html = '<span>Hello World</span>'
return p.toolkit.literal(html)

def get_helpers(self):
# This method is defined in the ITemplateHelpers interface and
# is used to return a dict of named helper functions.
return {'hello_world': hello_world}

Guidelines for writing extensions:
----------------------------------

Expand Down

0 comments on commit 98ad884

Please sign in to comment.