Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsingCircularTemplateContentReferenceError when using Eleventy snippets in Markdown #1237

Open
fragosti opened this issue Jun 6, 2020 · 10 comments

Comments

@fragosti
Copy link

fragosti commented Jun 6, 2020

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
@fragosti
Copy link
Author

fragosti commented Jun 6, 2020

This fixed it:

-    markdownTemplateEngine: 'njk',
+    markdownTemplateEngine: false,
   }

@fragosti fragosti closed this as completed Jun 6, 2020
@fragosti fragosti reopened this Jun 9, 2020
@fragosti
Copy link
Author

fragosti commented Jun 9, 2020

Re-opening as this is still an issue if you want to use nunchucks in your markdown.

@mpalpha
Copy link

mpalpha commented Jul 20, 2020

Re-opening as this is still an issue if you want to use nunchucks in your markdown.

Having the same issue here.

@TigersWay
Copy link
Contributor

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!

@TigersWay
Copy link
Contributor

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!

@gbirke
Copy link

gbirke commented May 3, 2021

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.

@jboolean
Copy link

jboolean commented Jun 6, 2022

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. 😕

@megheaiulian
Copy link

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.

@guilleliss
Copy link

guilleliss commented Feb 9, 2023

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

@guilleliss
Copy link

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 }}/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants