Now that we have twig, we can easily combine comment-block, comment-wrapper and comment into a single comments template, that contains a for loop, wrapper containers/classes and much simplified logic to hide/show title text, empty text, via preprocess functions.
Point 1: When does it ever really make sense to show a comment without it's wrapper?
Two answers:
- Drupal may print out a single comment, possibly without wrapper (not sure?) when previewing your comment submission.
- views.
I would argue that it's more work to theme a comment output, when its stripped of its wrapper container (and class). If rendering a single comment, just pass it to a unified comments template with one individual comment for the for loop, while hiding/unsetting the comments section title in a preprocess function. This will provide an avenue for consistent theming across the site, allowing you to actually make proper use of the container and wrapper class.
Point 2: The comment-wrapper and comment-block templates really don't give us anything that cannot be equally handled using preprocess and/or sub-pattern template suggestions.
- The section title text of the comment wrapper is shown in some places, while in other places (eg comment preview) we don't want to show this title text at all. Some sites would want to show "1 Comment" versus "2 Comments" in the title on some content types, but want to show "Reviews" etc for other content types. Overriding the default title text could be handled easily using a combination of sub-pattern template suggestions. Eg
function comments_preprocess_comments__comment_preview() { /* code to unset the "Comments" section title */ } - Forums: currently there is nasty logic in comment-wrapper template to remove the title for node type 'forum'. Were we to consolidate and start using sub-pattern template suggestions, this would be as easy as
function forum_preprocess_comments__forum() { /* code to unset the title */ } - Comment-block template provides a trivial one-liner logic statement to essentially display "No comments available" text if there are no comments. This is a single conditional that could easily be added to the top of a unified comments template that everyone would plainly understand. Eg
/*pseudocode*/ if not count(comments) print empty_text else enter for loop
Related:
Comments
Comment #1
jwilson3Added "comment-block" template to the summary above as well. IMHO there's no reason we need three templates here.
Comment #1.0
jwilson3Elaborated on reasons why we could get away with consolidation.
Comment #1.1
jwilson3Clean up html
Comment #1.2
jwilson3Updated summary statement first paragraph for clarity.
Comment #1.3
jwilson3Clean up point 2
Comment #2
jwilson3I'm thinking something like this:
At the theme layer, this consolidation would reduce 3 template files to 1 removing 6 template files total (if you include both bartik, comment module, and stark). The current three template files in stark twig theme constitute 53 lines of code across 3 files (including blank whitespace lines, not including the docblocks), and the code sample consolidation here would reduce that to 45 lines in a single file.
Comment #3
jwilson3Unsure, but this probably has less to do with the twig conversion, and more to do with component library...
Comment #3.0
jwilson3Clean up first and second point even more.