[ckan-dev] Customising the dataset form in 2.0

Toby Dacre toby.okfn at gmail.com
Thu Jan 24 03:24:13 UTC 2013


On 23 January 2013 19:59, Sean Hammond <sean.hammond at okfn.org> wrote:

> Hey, I just updated ckanext/example_idatasetform to work with CKAN 2.0:
>
> https://github.com/okfn/ckan/pull/295
>
> To add a new field to the dataset form I had to override four template
> files.
>
> templates/package/snippets/package_metadata_fields.html is where I add
> the dropdown select box for my new field. To construct the dropdown I
> need something that the plugin's setup_template_variables() adds to the
> template context. But c is not available in
> package_metadata_fields.html.
>
> So I have to override the parent template that calls
> package_metadata_fields.html and make it pass the extra data in. But c
> is not available in the parent either, so I have to override the
> template that calls that, and the template that calls that!
>
> I think anyone trying to use a tag vocabulary, for example, would need
> to do this.
>
> Am I doing something wrong? Or should the templates be changed in CKAN so
> that c is passed into the sub-templates?
>
> Currently this is by design to keep the snippets clean.  The reason is so
that snippets can be included in any templates and are passed the required
data which may be in a different variable in different pages.  If we pass c
then we will end up with people creating snippets that are not reusable.

As to the best solution,  I'm not sure.  I think that part of the problem
here is the depth of the calls template -> snippet -> snippet -> snippet.
It would be nicer if this was a bit simpler but I understand why it has
been done this way.  I'd also be happy with something like
c.snippet_context which would appear as c in snippets but that might be
even more confusing.

> _______________________________________________
> 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/20130124/50e6cafd/attachment-0001.html>


More information about the ckan-dev mailing list