eleventy
eleventy copied to clipboard
UsingCircularTemplateContentReferenceError when using Eleventy snippets in Markdown
Describe the bug When using
<ul>
{%- for post in collections.post | reverse | limit(postsListLimit) -%}
<li class="py-3">
<h3>
<a href="{{ post.url | url }}">{{ post.data.title }}</a>
</h3>
<label>
{{ post.date | dateReadable }}
</label>
<p class="line-clamp py-1">
{% excerpt post %}
</p>
</li>
{%- endfor -%}
</ul>
In my markdown, I get
> ./src/site/index.njk contains a circular reference (using collections) to its own templateContent.
`UsingCircularTemplateContentReferenceError` was thrown:
UsingCircularTemplateContentReferenceError: ./src/site/index.njk contains a circular reference (using collections) to its own templateContent.
at TemplateMap.populateContentDataInMap (/Users/francescoagosti/Projects/blog/node_modules/@11ty/eleventy/src/TemplateMap.js:382:17)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
Copied 1 item / Wrote 0 files in 0.09 seconds (v0.10.0)
I get this for other syntax as well, like when using:
{% include "components/postslist.njk" %}
My markdown-it config is
eleventyConfig.setLibrary(
'md',
markdownIt({ html: true })
.use(markdownItAnchor, {
permalink: true,
permalinkSymbol: '<i data-feather="link" class="link"></i>',
})
.use(markdownItLinkAttr, {
// Make external links open in a new tab.
pattern: /^https?:\/\//,
attrs: {
target: '_blank',
rel: 'noopener noreferrer',
},
})
)
Expected behavior For eleventy not to process the template code in markdown code snippets.
Environment:
- OS and Version: Mac OS Sierra
- Eleventy Version: 0.11.0
This fixed it:
- markdownTemplateEngine: 'njk',
+ markdownTemplateEngine: false,
}
Re-opening as this is still an issue if you want to use nunchucks in your markdown.
Re-opening as this is still an issue if you want to use nunchucks in your markdown.
Having the same issue here.
Same issue too here.... But very different environment! Windows 10, eleventy last commit from github, nunjucks templates
~= 2000 articles, but 3 with a link to a perfectly working page give that message. No idea where to go from there!
Same issue too here.... But very different environment! Windows 10, eleventy last commit from github, nunjucks templates
Not really... Just some trouble with eleventyComputed
which needed to go too deep!
I was having the same issue with a liquid template (for rendering tags with post excerpts), so the problem seems to be universal. I also use the excerpt
short code (with a custom function), so I guess the access to templateContent
inside the excerpt function might be the culprit.
I have solved the problem (rather clumsily) with the following code snippet at the top of my excerpt
function:
function excerpt(post){
// list of template pages that iterate over post
const iteratingTemplates = ['./src/index.liquid', './src/tags.liquid'];
if (iteratingTemplates.indexOf(post.inputPath)>-1) {
return null;
}
// now extract the excerpt from post.templateContent
}
Of course this means that templates which contain lists can never have excerpts and that you have to add your specific template names to your custom excerpt function. A better approach would probably be to check somewhere in post.template
if the template matches post.inputPath
, preventing a post from trying to excerpt itself. But I don't know enough how 11ty works to know where to look for that information or if such an approach is even possible.
I'm trying to render one collection from an item in another collection, and I get this error. I see nothing circular about it. Turning off markdownTemplateEngine
does not resolve it. 😕
Came across this issue too. Turns out that the problem was that 11ty didn't knew about the collections used. Using eleventyImport front matter config fixed the problem. See https://www.11ty.dev/docs/collections/#declare-your-collections-for-incremental-builds and https://github.com/11ty/eleventy/issues/975.
Came across this issue too. Turns out that the problem was that 11ty didn't knew about the collections used. Using eleventyImport front matter config fixed the problem. See https://www.11ty.dev/docs/collections/#declare-your-collections-for-incremental-builds and #975.
Thanks, it seems that this might work, but I do not understand how to use it. I have the same issue, getting a warning for UsingCircularTemplateContentReferenceError
when using templateContent
within the excerpt shortcode in a tags template
I managed to solve this but filtering all
from the collections in the tags template, this is the tags template:
---
layout: base
pagination:
data: collections
size: 1
alias: tag
filter:
- post
- all
permalink: /tags/{{ tag }}/