Feedback on Giscus Comments - Conditional property not working #719
bwipinfo-creator
started this conversation in
General
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Thank you very much for the plugin and all the hard work.
I now have a site up and running, behind a password.
I am using Obsidian, Github, Cloudflare.
I have had some trouble trying to get some pages to show the comments and others not.
I have tried a bunch of solutions, with Gemini and Claude assistance.... i am very new to this to please forgive me.
Below is the summary that Claude generated for me on what we did in the hope that it might assist with future development. If i have completely missed something, which is entirely likely, my apologies!
Issue: Frontmatter properties not accessible in custom component scope
Plugin Version: Latest (as of October 2025) 2.59.2
Eleventy Version: 2.0.1
Environment: Cloudflare Pages deployment
Summary
Custom components in src/site/_includes/components/user/notes/afterContent/ cannot access frontmatter properties from the notes being rendered, making it impossible to conditionally display components based on note-specific metadata.
What Works
The dynamics.js data file correctly discovers .njk files in the afterContent directory:
=== AFTERCONTENT DEBUG ===
Path searched: src/site/_includes/components/user/notes/afterContent
Files found: [ 'components/user/notes/afterContent/giscus.njk' ]
The layout file (note.njk) correctly includes components via the loop:
njk{% for imp in dynamics.notes.afterContent %}
{% include imp %}
{% endfor %}
Components render successfully when they have no conditional logic.
What Doesn't Work
Custom components cannot access frontmatter properties from the parent note. All of these approaches fail:
Attempt 1:
njk{%- if page.dg-comments -%}
{%- endif -%}
Attempt 2:
njk{%- if dg-comments -%}
{%- endif -%}
Attempt 3:
njk{%- if page['dg-comments'] -%}
{%- endif -%}
Attempt 4: Using camelCase property name
njk{%- if dgComments -%}
{%- endif -%}
None of these conditionals evaluate to true, even when the note's frontmatter contains:
yaml---
dg-comments: true
dg-publish: true
Evidence of Scope Issue
When we add a hardcoded include directly in note.njk:
njk{% include "components/user/notes/afterContent/giscus.njk" %}
The component renders, proving the file exists and the template syntax is valid. However, the conditional still doesn't work, suggesting that frontmatter variables are not being passed to the included component's scope.
Suspected Root Cause
The Nunjucks {% include %} statement in the loop ({% for imp in dynamics.notes.afterContent %}) may not be passing the current page context to the included templates.
In Eleventy/Nunjucks, included templates inherit the parent scope by default, but when includes are referenced via string variables (as in {% include imp %}), the scope inheritance may not work as expected.
Suggested Fix
The loop in note.njk may need to explicitly pass context:
Current (doesn't work):
njk{% for imp in dynamics.notes.afterContent %}
{% include imp %}
{% endfor %}
Suggested (untested):
njk{% for imp in dynamics.notes.afterContent %}
{% include imp with {
'dg-comments': page['dg-comments'],
dgComments: dgComments,
page: page
} %}
{% endfor %}
Or potentially all page variables need to be explicitly passed when using dynamic includes.
Reproduction Steps
Create src/site/_includes/components/user/notes/afterContent/test.njk:
njk{%- if page['dg-comments'] -%}
Add to a note's frontmatter:
yaml---
dg-comments: true
dg-publish: true
Publish the note
Component renders but conditional content does not appear
Expected Behavior
Custom components in afterContent should have access to the current note's frontmatter properties, allowing developers to conditionally display features (like comments, donation buttons, etc.) on a per-note basis.
Workaround
Currently, the only workaround is to remove conditionals and display components on all pages, or modify the core note.njk layout file directly rather than using the custom components system.
Additional Context
This issue was discovered while attempting to implement Giscus comments following the official documentation at https://dg-docs.ole.dev/advanced/adding-custom-components/. The documentation suggests this should work but doesn't explain how to access frontmatter properties within custom components.
Beta Was this translation helpful? Give feedback.
All reactions