Skip to content

Commit 7463bd6

Browse files
authored
Fix issue with Comment replies block not working (#1440)
The Comment template has a `replies` block allowing devs to customize how replies are output. This block was not working correctly because it was nested inside another embed. This PR uses `set` to define the replies outside of the embed and then pass them in.
1 parent af70c79 commit 7463bd6

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.changeset/large-teachers-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Fix issue with Comment `replies` block not working

src/components/comment/comment.twig

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,27 @@
113113
<h{{_section_heading_depth}} class="u-hidden-visually">
114114
Replies to {{comment.author.name}}
115115
</h{{_section_heading_depth}}>
116+
117+
{#
118+
This is defined here, so we can pass it into the block of a nested embed.
119+
@see https://benfurfie.co.uk/articles/how-to-nest-a-block-in-another-block-in-an-embed-in-twig
120+
#}
121+
{% set repliesContent %}
122+
{% block replies %}
123+
{% for child in comment.children %}
124+
{% include '@cloudfour/components/comment/comment.twig' with {
125+
comment: child,
126+
heading_depth: _child_heading_depth,
127+
} only %}
128+
{% endfor %}
129+
{% endblock %}
130+
{% endset %}
131+
116132
{% embed '@cloudfour/objects/rhythm/rhythm.twig' with {
117133
class: 'c-comment__replies'
118134
} %}
119135
{% block content %}
120-
{% block replies %}
121-
{% for child in comment.children %}
122-
{% include '@cloudfour/components/comment/comment.twig' with {
123-
comment: child,
124-
heading_depth: _child_heading_depth,
125-
} only %}
126-
{% endfor %}
127-
{% endblock %}
136+
{{ repliesContent }}
128137
{% endblock %}
129138
{% endembed %}
130139
{% endif %}

0 commit comments

Comments
 (0)