Skip to content

Commit

Permalink
[#847] Add beginning of theming best practices page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Nov 27, 2013
1 parent cacb133 commit e98dfc7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions doc/theming/best-practices.rst
@@ -0,0 +1,52 @@
======================================
Best practices for writing CKAN themes
======================================

-----------------
Use ``url_for()``
-----------------

Always use :py:func:`~ckan.lib.helpers.url_for` (available to templates as
``h.url_for()``) when linking to other CKAN pages, instead of hardcoding URLs
like ``<a href="/dataset">``. Links created with
:py:func:`~ckan.lib.helpers.url_for` will update themselves if the URL routing
changes in a new version of CKAN, or if a plugin changes the URL routing.

-------------------------------
Use ``_()`` and ``ungettext()``
-------------------------------

Always use :py:func:`_` (or, if pluralizaton is needed, :py:func:`ungettext`)
to mark user-visible strings for localization.

-----------------------------------------------------------------
Helper function names should begin with the name of the extension
-----------------------------------------------------------------

Namespacing helper functions in this way avoids accidentally overriding, or
being overriden by, a core helper function, or a helper function from another
extension. For example::

example_theme_most_popular_groups


-------------------------------------------------------------
Snippet filenames should begin with the name of the extension
-------------------------------------------------------------

Namespacing snippets in this way avoids accidentally overriding, or being
overridden by, a core snippet, or a snippet from another extension.
For example::

ckanext-example_theme/ckanext/example_theme/templates/snippets/example_theme_most_popular_groups.html


--------------------------------------------
Use ``{% snippet %}``, not ``{% include %}``
--------------------------------------------

Always use CKAN's custom ``{% snippet %}`` instead of Jinja's default
``{% include %}`` tag. Snippets can only access certain global variables, and
any variables explicitly passed to them by the calling template. They don't
have access to the full context of the calling template, as included files do.
This makes snippets much easier to debug.
1 change: 1 addition & 0 deletions doc/theming/index.rst
Expand Up @@ -43,6 +43,7 @@ your custom CKAN theme.
static-files
css
javascript
best-practices
jinja-tags
variables-and-functions
template-helper-functions
Expand Down

0 comments on commit e98dfc7

Please sign in to comment.