Skip to content

Commit

Permalink
Add example of template rendering to TableBlock docs
Browse files Browse the repository at this point in the history
Addresses #5540
  • Loading branch information
gasman authored and lb- committed Oct 11, 2019
1 parent 72ba719 commit a0035c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Changelog
* Added ARIA role to TableBlock output (Matt Westcott)
* Added cache-busting query parameters to static files within the Wagtail admin (Matt Westcott)
* Allow `register_page_action_menu_item` and `construct_page_action_menu` hooks to override the default menu action (Rahmi Pruitt, Matt Westcott)
* Add docs table template rendering example (Matt Westcott)
* Fix: Added line breaks to long filenames on multiple image / document uploader (Kevin Howbrook)
* Fix: Added https support for Scribd oEmbed provider (Rodrigo)
* Fix: Changed StreamField group labels color so labels are visible (Catherine Farman)
Expand Down
25 changes: 24 additions & 1 deletion docs/reference/contrib/table_block.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Basic Usage

After installation, the TableBlock module can be used in a similar fashion to other StreamField blocks in the Wagtail core.

Just import the TableBlock ``from wagtail.contrib.table_block.blocks import TableBlock`` and add it to your StreamField declaration.
Import the TableBlock ``from wagtail.contrib.table_block.blocks import TableBlock`` and add it to your StreamField declaration.

.. code-block:: python
Expand All @@ -35,6 +35,29 @@ Just import the TableBlock ``from wagtail.contrib.table_block.blocks import Tabl
table = TableBlock()
Then, on your page template, the ``{% include_block %}`` tag (called on either the individual block, or the StreamField value as a whole) will render any table blocks it encounters as an HTML ``<table>`` element:

.. code-block:: html+django

{% load wagtailcore_tags %}

{% include_block page.body %}

Or:

.. code-block:: html+django

{% load wagtailcore_tags %}

{% for block in page.body %}
{% if block.block_type == 'table' %}
{% include_block block %}
{% else %}
{# rendering for other block types #}
{% endif %}
{% endfor %}


Advanced Usage
--------------

Expand Down
1 change: 1 addition & 0 deletions docs/releases/2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Other features
* Added ARIA role to TableBlock output (Matt Westcott)
* Added cache-busting query parameters to static files within the Wagtail admin (Matt Westcott)
* Allow ``register_page_action_menu_item`` and ``construct_page_action_menu`` hooks to override the default menu action (Rahmi Pruitt, Matt Westcott) - thanks to `The Motley Fool <https://www.fool.com/>`_ for sponsoring review of this feature
* Add docs table template rendering example (Matt Westcott)


Bug fixes
Expand Down

0 comments on commit a0035c3

Please sign in to comment.