Demo theme: allow disabling comments per blog post (per-post toggle)
Demo theme: allow disabling comments per blog post (per-post toggle)
Summary
The demo blog always renders the comment list and comment form on every post (themes/demo/pages/blog/post.htm). There is currently no supported way to disable comments for an individual post — the only options are deleting all comments or removing the comment section from the template (which disables comments globally).
Moderating per post is a very common real-world requirement (e.g. closing comments on older or sensitive posts), so the demo theme would ideally demonstrate how to model it.
Current behavior (4.x)
-themes/demo/pages/blog/post.htm (lines 84–91) unconditionally renders:
{% partial 'blog/comment-list' %}
...
{% ajaxPartial 'blog/comment-form' %}-themes/demo/blueprints/fields/_blog_content.yaml (the Fields\BlogContent mixin, shared by the regular_post and markdown_post groups of Blog\Post) has no field to control comment availability.
Proposed enhancement
1. Add a checkbox field to the shared content mixin (themes/demo/blueprints/fields/_blog_content.yaml):
comments_enabled:
tab: Manage
label: Kommentare erlauben / Enable Comments
commentAbove: 'Haken entfernen, um den Kommentarbereich für diesen Beitrag auszublenden'
type: checkbox
default: trueBecause it lives in the Fields\BlogContent mixin, it automatically appears on both post types (Regular Post and Markdown Post) without duplicating the field per group.
2. Wrap the comment section in themes/demo/pages/blog/post.htm:
{% if post.comments_enabled|default(true) %}
<div class="card-divider"></div>
<div class="card-body card-lg">
{% partial 'blog/comment-list' %}
</div>
<div class="card-divider"></div>
<div class="card-body card-lg">
{% ajaxPartial 'blog/comment-form' %}
</div>
{% endif %}Implementation notes
-default: true keeps existing behavior: all posts keep comments after php artisan tailor:migrate (Tailor adds the column safely; per its docs it never drops columns or data on existing installs).
-The |default(true) filter in the template keeps the page rendering even if tailor:migrate has not been run yet — the section then simply stays visible, exactly like today.
-Unchecking the box hides both the comment list and the form for that single post; all other posts are unaffected.
-If desired, the comment form partial could additionally be disabled via the component, but the template-level check is the minimal, easy-to-understand demo approach.
Workaround today
Theme authors must add the field and conditional themselves (as we did in a production theme based on the demo) or remove the comment section from post.htm entirely.
Source: octobercms/october