@@ -654,7 +654,7 @@ Embedded Components
654
654
Embedded components were added in TwigComponents 2.2.
655
655
656
656
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
658
658
*slots * which you may be familiar with from Vue. The ``component `` tag is very
659
659
similar to Twig's native `embed tag `_.
660
660
@@ -670,8 +670,8 @@ blocks for the cells and an optional footer:
670
670
<thead>
671
671
<tr>
672
672
{% for header in this.headers %}
673
- <th>
674
- {% block th %}{{ header }}{% endblock % }
673
+ <th class="{% block th_class %}data-table-header{% endblock %}" >
674
+ {{ header }}
675
675
</th>
676
676
{% endfor %}
677
677
</tr>
@@ -680,33 +680,34 @@ blocks for the cells and an optional footer:
680
680
{% for row in this.data %}
681
681
<tr>
682
682
{% for cell in row %}
683
- <td>
684
- {% block td %}{{ cell }}{% endblock % }
683
+ <td class="{% block td_class %}data-table-cell{% endblock %}" >
684
+ {{ cell }}
685
685
</td>
686
686
{% endfor %}
687
687
</tr>
688
688
{% endfor %}
689
689
</tbody>
690
690
</table>
691
- {% if block('footer') is defined %}
692
- <div class="data-table-footer">
693
- {{ block('footer') }}
694
- </div>
695
- {% endif %}
691
+ {% block footer %}{% endblock %}
696
692
</div>
697
693
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 .
699
695
The ``with `` data is what's mounted on the component object.
700
696
701
697
.. code-block :: twig
702
698
703
699
{# templates/some_page.html.twig #}
704
700
705
701
{% 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 %}
708
705
709
- {% block footer %}My footer{% endblock %}
706
+ {% block footer %}
707
+ <div class="data-table-footer">
708
+ My footer
709
+ </div>
710
+ {% endblock %}
710
711
{% endcomponent %}
711
712
712
713
.. note ::
0 commit comments