[ckan-dev] RFC snippets

Sean Hammond sean.hammond at okfn.org
Fri Apr 13 12:45:03 UTC 2012


Btw, do we need both templates/_snippet and templates/snippets?

On Thu, Apr 12, 2012 at 12:05:19PM +0100, Toby Dacre wrote:
> 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).

> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev





More information about the ckan-dev mailing list