From 95b374cda69e0d602701664f62db3471fe0e4b96 Mon Sep 17 00:00:00 2001 From: Paul Hebert Date: Fri, 23 Jul 2021 15:06:25 -0700 Subject: [PATCH 1/2] Fix issue with Comment `replies` block not working 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. --- src/components/comment/comment.stories.mdx | 4 +++- src/components/comment/comment.twig | 25 +++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/comment/comment.stories.mdx b/src/components/comment/comment.stories.mdx index 10b76322b..cae31834d 100644 --- a/src/components/comment/comment.stories.mdx +++ b/src/components/comment/comment.stories.mdx @@ -109,7 +109,9 @@ It is helpful for context within a discussion to know when a commentor is the or {(args) => { useEffect(() => initCommentReplyForms()); return authorDemo({ - comment: makeComment(), + comment: makeComment({ + replies: 2, + }), allow_replies: args.allowReplies, demo_post_author: true, logged_in_user: args.isLoggedIn ? tyler : null, diff --git a/src/components/comment/comment.twig b/src/components/comment/comment.twig index 53065e25c..d77e052f6 100644 --- a/src/components/comment/comment.twig +++ b/src/components/comment/comment.twig @@ -113,18 +113,27 @@ Replies to {{comment.author.name}} + + {# + This is defined here, so we can pass it into the block of a nested embed. + @see https://benfurfie.co.uk/articles/how-to-nest-a-block-in-another-block-in-an-embed-in-twig + #} + {% set repliesContent %} + {% block replies %} + {% for child in comment.children %} + {% include '@cloudfour/components/comment/comment.twig' with { + comment: child, + heading_depth: _child_heading_depth, + } only %} + {% endfor %} + {% endblock %} + {% endset %} + {% embed '@cloudfour/objects/rhythm/rhythm.twig' with { class: 'c-comment__replies' } %} {% block content %} - {% block replies %} - {% for child in comment.children %} - {% include '@cloudfour/components/comment/comment.twig' with { - comment: child, - heading_depth: _child_heading_depth, - } only %} - {% endfor %} - {% endblock %} + {{ repliesContent }} {% endblock %} {% endembed %} {% endif %} From efd3e74909f285f1e1c7f8fb58106afc7b507103 Mon Sep 17 00:00:00 2001 From: Paul Hebert Date: Fri, 23 Jul 2021 15:07:26 -0700 Subject: [PATCH 2/2] Commit right stuff --- .changeset/large-teachers-roll.md | 5 +++++ src/components/comment/comment.stories.mdx | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .changeset/large-teachers-roll.md diff --git a/.changeset/large-teachers-roll.md b/.changeset/large-teachers-roll.md new file mode 100644 index 000000000..5aad4450e --- /dev/null +++ b/.changeset/large-teachers-roll.md @@ -0,0 +1,5 @@ +--- +'@cloudfour/patterns': patch +--- + +Fix issue with Comment `replies` block not working diff --git a/src/components/comment/comment.stories.mdx b/src/components/comment/comment.stories.mdx index cae31834d..10b76322b 100644 --- a/src/components/comment/comment.stories.mdx +++ b/src/components/comment/comment.stories.mdx @@ -109,9 +109,7 @@ It is helpful for context within a discussion to know when a commentor is the or {(args) => { useEffect(() => initCommentReplyForms()); return authorDemo({ - comment: makeComment({ - replies: 2, - }), + comment: makeComment(), allow_replies: args.allowReplies, demo_post_author: true, logged_in_user: args.isLoggedIn ? tyler : null,