Skip to content

Commit

Permalink
[#847] Clarify about variables passed into snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Sep 12, 2013
1 parent 0af3d0d commit bc08d24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions ckanext/example_theme/v8_snippet/templates/home/index.html
Expand Up @@ -5,6 +5,7 @@
{{ h.recently_changed_packages_activity_stream() }}

<h3>Dataset of the day</h3>
{# Call the package_item.html snippet. #}
{% snippet 'snippets/package_item.html',
package=h.example_theme_dataset_of_the_day() %}

Expand Down
17 changes: 12 additions & 5 deletions doc/theming.rst
Expand Up @@ -522,11 +522,18 @@ Let's change our |index.html| file to call this snippet:

.. literalinclude:: ../ckanext/example_theme/v8_snippet/templates/home/index.html

The ``{% snippet %}`` tag takes one or more arguments. The first argument is
the name of the snippet to call. Any further arguments will be passed into
the snippet as parameters. As in the ``package_item.html`` docstring above,
each snippet's docstring should document the parameters it requires. In this
example was pass just one parameter to the snippet: the dataset to be rendered.
Here we pass two arguments to the ``{% snippet %}`` tag:

.. literalinclude:: ../ckanext/example_theme/v8_snippet/templates/home/index.html
:start-after: {# Call the package_item.html snippet. #}
:end-before: {% endblock %}

the first argument is the name of the snippet file to call. The second
argument, separated by a comma, is the package to pass into the snippet. After
the filename you can pass any number of variables into a snippet, and these
will all be available to the snippet code as top-level global variables. As in
the ``package_item.html`` docstring above, each snippet's docstring should
document the parameters it requires.

If you reload your `CKAN front page`_ in your web browser now, you should see
the dataset of the day rendered nicely.
Expand Down

0 comments on commit bc08d24

Please sign in to comment.