Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#847] Add beginning of theming best practices page
- Loading branch information
Sean Hammond
committed
Nov 27, 2013
1 parent
cacb133
commit e98dfc7
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters