Skip to content

Commit 3692519

Browse files
kbondweaverryan
andcommitted
Apply suggestions from code review
Co-authored-by: Ryan Weaver <weaverryan+github@gmail.com>
1 parent 142b273 commit 3692519

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/TwigComponent/src/Resources/doc/index.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Embedded Components
654654
Embedded components were added in TwigComponents 2.2.
655655

656656
You can write your component's Twig template with blocks that can be overridden
657-
when rendering using the ``{% component %}``. These blocks can be thought of as
657+
when rendering using the ``{% component %}`` syntax. These blocks can be thought of as
658658
*slots* which you may be familiar with from Vue. The ``component`` tag is very
659659
similar to Twig's native `embed tag`_.
660660

@@ -670,8 +670,8 @@ blocks for the cells and an optional footer:
670670
<thead>
671671
<tr>
672672
{% for header in this.headers %}
673-
<th>
674-
{% block th %}{{ header }}{% endblock %}
673+
<th class="{% block th_class %}data-table-header{% endblock %}">
674+
{{ header }}
675675
</th>
676676
{% endfor %}
677677
</tr>
@@ -680,33 +680,34 @@ blocks for the cells and an optional footer:
680680
{% for row in this.data %}
681681
<tr>
682682
{% for cell in row %}
683-
<td>
684-
{% block td %}{{ cell }}{% endblock %}
683+
<td class="{% block td_class %}data-table-cell{% endblock %}">
684+
{{ cell }}
685685
</td>
686686
{% endfor %}
687687
</tr>
688688
{% endfor %}
689689
</tbody>
690690
</table>
691-
{% if block('footer') is defined %}
692-
<div class="data-table-footer">
693-
{{ block('footer') }}
694-
</div>
695-
{% endif %}
691+
{% block footer %}{% endblock %}
696692
</div>
697693
698-
When rendering, you can override the ``th``, ``th`` blocks and add a ``footer`` block.
694+
When rendering, you can override the ``th_class``, ``td_class``, and ``footer`` blocks.
699695
The ``with`` data is what's mounted on the component object.
700696

701697
.. code-block:: twig
702698
703699
{# templates/some_page.html.twig #}
704700
705701
{% component table with {headers: ['key', 'value'], data: [[1, 2], [3, 4]]} %}
706-
{% block th %}custom th ({{ parent() }}){% endblock %}
707-
{% block td %}custom td ({{ parent() }}){% endblock %}
702+
{% block th_class %}{{ parent() }} text-bold{% endblock %}
703+
704+
{% block td_class %}{{ parent() }} text-italic{% endblock %}
708705
709-
{% block footer %}My footer{% endblock %}
706+
{% block footer %}
707+
<div class="data-table-footer">
708+
My footer
709+
</div>
710+
{% endblock %}
710711
{% endcomponent %}
711712
712713
.. note::

0 commit comments

Comments
 (0)