[ckan-dev] Custom function for custom extension

Jorge Pantoja jorgepantojam at gmail.com
Tue Jul 9 12:47:01 UTC 2013


Hi Hendrik! Thanks a lot for the information. Ive changed my PluginClass as
you said in order to do that.

However, when I include "p.implements(plugins.ITemplateHelpers, inherit=True)"
in the class, I got an error on the whole ckan portal: "Internal Server
Error, The server encountered an internal error....."

any idea what could be the problem?


Jorge



On Tue, Jul 9, 2013 at 1:17 PM, Hendrik Bunke <bunke.hendrik at gmail.com>wrote:

>
>
> --On 2013-07-09 00:24, Jorge Pantoja wrote:
> > Hi everyone,
> >
> > Im trying to do a custom extension to create a sparql interface in order
> to
> > communicate with a sparql point I have installed (since it is in a local
> > network that cannot be accessed from outside). Im using sparql wrapper (
> > http://sparql-wrapper.sourceforge.net/) to do that.
> >
> > I need to call a python function in the jinja template in order to send
> the
> > query and display the results in the screen.
> >
> > However, I dont know how to setup the function correctly in the ckan
> jinja
> > environment, so I can use it in the template.
> >
> > Can you help me telling me how to do that correctly?
>
> Hi,
>
> basically you would do the following to get functions in
> templates:
>
> -   your PluginClass should implement ckan.plugins.ITemplateHelpers
>     (ckan.plugins.implements.ITemplateHelpers, inherit=True)
> -   define your helper function
> -   define a get_helpers() in your Plugin Class:
>     def get_helpers(self):
>         return {'your_key': your_above_defined_helper_function }
> -   you can then get your function into whatever block inside the
>     template:
>     {% set your_key = h.your_key() %}
>     and then place the result as variable, e.g.
>     <p>{{ your_key }}</p>
>
> It's also (shortly) described in the docs:
>
> http://docs.ckan.org/en/ckan-2.0/extensions.html#module-ckan.plugins.interfaces
> (search for the TemplateHelpers Interface). Also have a look at
> the example extensions.
>
> hope that helps
> hendrik
>
>
> --
> Dr. Hendrik Bunke
> http://gplus.to/hbunke
> http://twitter.com/hbunke
> http://www.hbxt.org
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130709/dc7b118e/attachment-0001.html>


More information about the ckan-dev mailing list