[ckan-dev] template code duplication and complexity - some thoughts

Toby Dacre toby.okfn at gmail.com
Tue Nov 13 15:16:45 UTC 2012


On 13 November 2012 14:54, John Martin <john.martin.okfn at gmail.com> wrote:

> Hey Toby,
>
> I've setup a branch for some of these tweaks:
>
> https://github.com/okfn/ckan/tree/3016-template-tweaks
>
> 1) follower numbers is effectively repeated in user/read.html and
> ajax_snippets/popover-context-user.html (that template name also breaks the
> template naming conventions should be popover_context_user.html)
>
> This is a little more complex than perhaps it seems at first. The
> ajax_snippet one doesn't have {{ user }} as a context and therefore can't
> really share the same snippet as the read.html (it's getting it's template
> variables as get variables via the get_snippet method)
>

h.snippet(..) should be fine it is designed for this type of usage you can
pass different vars to the snippet

I can fix this if you want - let me know


> Additionally the class="nums" seems very generic maybe "follower_numbers"?
>
> It is generic deliberately because the code is used with packages, groups
> and users. Also these numbers are not just limited to the follower count.
>
ok I've seen this now with the dataset info maybe a nicer class name 'nums'
seems a bit too general but can't think of a better one

> 2) in user/read.html having the user info (sidebar) as a snippet would
> allow easier customization
>
> Not sure I agree. The format that the data will appear as will only ever
> be in the left column of user/read pages. Why would adding more template
> spaghetti help with customization since all user/read pages extend from it?
> (I've added a block around it though)
>
what if we wanted it on the dashboard?  I agree that things can be a bit
spagetti - I'm less worried now there is a read_base.html though.  extra
blocks are always good.

> 3) in user/read.html having the 'section tabs' as a snippet would make it
> easier to add/remove tabs for custom needs at least having the tabs in
> their own block to allow easy replacement.
>
> Yes. We now have snippets/page_header.html
>
As my other email/comment actually as this is just a <ul> maybe a snippet
is overkill but I'm keen to add the items via template helpers

> 4) with user/read.html as it has now expanded to multiple uses should we
> not create a proper user/read_base.html (better name though) rather than
> dual using user/read.html for both a template base and for showing
> datasets?
>
> Yeah, seems fair. I've done this in the branch.
>

thanks

>
> Cheers,
> .jm
>
> On Monday, 12 November 2012 at 12:00, ckan-dev-request at lists.okfn.orgwrote:
>
> Send ckan-dev mailing list submissions to
> ckan-dev at lists.okfn.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> or, via email, send a message with subject or body 'help' to
> ckan-dev-request at lists.okfn.org
>
> You can reach the person managing the list at
> ckan-dev-owner at lists.okfn.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of ckan-dev digest..."
>
>
> Today's Topics:
>
> 1. template code duplication and complexity - some thoughts
> (Toby Dacre)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 12 Nov 2012 11:56:48 +0000
> From: Toby Dacre <toby.okfn at gmail.com>
> Subject: [ckan-dev] template code duplication and complexity - some
> thoughts
> To: CKAN Development Discussions <ckan-dev at lists.okfn.org>
> Message-ID:
> <CAKZ3V-MH9Nx=s+AYNSRQceRkrzXw3qMkLc_CeD6C_HAyY-=Caw at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> The templates seem to be starting to get a bit complex and contain code
> duplication
>
> examples
>
> 1) follower numbers is effectively repeated in user/read.html and
> ajax_snippets/popover-context-user.html (that template name also breaks the
> template naming conventions should be popover_context_user.html)
>
> If a snippet was used then that would make it easier for customisation by
> customers. eg not showing number of edits
>
> Additionally the class="nums" seems very generic maybe "follower_numbers"?
>
> 2) in user/read.html having the user info (sidebar) as a snippet would
> allow easier customization
>
> 3) in user/read.html having the 'section tabs' as a snippet would make it
> easier to add/remove tabs for custom needs at least having the tabs in
> their own block to allow easy replacement.
>
> 4) with user/read.html as it has now expanded to multiple uses should we
> not create a proper user/read_base.html (better name though) rather than
> dual using user/read.html for both a template base and for showing
> datasets?
>
> Keeping the templates clean simple and well separated makes
> customization/expansion far easier so I think is worth the effort
> especially as it will have long term impacts as once 2.0 is released
> changing templates/blocks etc can cause compatibility issues between
> versions
>
> cheers
> Toby
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://lists.okfn.org/pipermail/ckan-dev/attachments/20121112/8e36b20a/attachment-0001.htm
> >
>
> ------------------------------
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/optionss/ckan-dev
>
>
> End of ckan-dev Digest, Vol 25, Issue 15
> ****************************************
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20121113/c8da8ac6/attachment-0001.html>


More information about the ckan-dev mailing list