[ckan-dev] RFC snippets
Toby Dacre
toby.okfn at gmail.com
Thu Apr 12 11:05:19 UTC 2012
Hi,
As work on cleaning our templates and aiding reuse/avoiding duplication
I've prototyped some snippet functionality.
The idea is to have a folder of snippets in templates that can then be
rendered as needed via a helper function. This helps reduce the
size/complexity of _util.html etc. It allows individual page components to
be easily customised by extensions without duplicating content which
remains identical.
example:
${h.snippet('package_list', packages=packages)}
This renders the template "snippets/package_list.html" passing {'packages'
: packages} and inserts it into the page.
Multiple keywords can be passed as needed which allows us to easily create
snippets from our existing xhtml
Any Genshi filters are applied to the rendered html
Issues:
Should we be more explicit in passing the full template name?
Currently render() is partly reimplemented in snippet() - only about 10
lines of code for the whole function - is this a bad idea and all rendering
should go through a single renderer?
Can anyone think of why snippets are a bad idea?
Any other thoughts?
Toby
PS I've also made a convert_to_dict() helper function so that we can remove
further duplication in _util.html eg package_list() and
package_list_from_dict() which seems to work happily (at least for those
particular functions).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20120412/e21aa0bc/attachment.html>
More information about the ckan-dev
mailing list