eleventy: eleventyComputed is not returning data

---
pagination:
  data: standards
  size: 1
  alias: standard
  addAllPagesToCollections: true
permalink: "{{ standard.slug }}/index.html"
eleventyComputed:
  title: "{{ standard.name }}"
---

Doesn’t return anything for the <title>.

Prior, I was using {% set title = standard.name %}, but this doesn’t get elevated to collections.all (returns empty for dynamic pages)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

@jasonday to access computed variables, use:

{{ eleventyComputed.title }}

If you’re also sometimes using {{ title }}, then do this:

{{ title or eleventyComputed.title }}

@jasonday to access computed variables, use:

{{ eleventyComputed.title }}

If you’re also sometimes using {{ title }}, then do this:

{{ title or eleventyComputed.title }}

Is this by design? I figured it out via trial-and-error, but somehow the documentation had left me with an assumption that the eleventyComputed contents would be “woven in” and override page data.

I have similar problems with Nunjuck templates in computed data properties. Some values from the data cascade seem to be accessible (e.g. title) while others don’t (e.g. collections). I setup a test repository to demonstrate my issue. If I use javascript front matter in src/posts/posts.njk everything is working as expected.

dweidner/eleventy-computed-front-matter

I also tried the current master branch, same problems. Could it be that collections are simply not yet available at that point of time?

Giving unexpected results:

---
layout: archive.njk
title: Posts
tags: false
permalink: "/"
eleventyComputed:
  total: "{{ collections.post | length }}"
---
<dl>
  <dt>EleventyComputed</dt>
  <dd>{{ total }}</dd>
  <dt>Template</dt>
  <dd>{{ collections.post | length }}</dd>
</dl>

Works as expected:

---js
{
  layout: 'archive.njk',
  title: 'Posts',
  tags: false,
  permalink: '/',
  eleventyComputed: {
    total({collections}) {
        return collections.post.length;
    }
  }
}
---
<dl>
  <dt>EleventyComputed</dt>
  <dd>{{ total }}</dd>
  <dt>Template</dt>
  <dd>{{ collections.post | length }}</dd>
</dl>

@jasonday are you still interested in this issue, or should I close it?

Sorry, I haven’t had time to create a test case and ended up using renderData, which did work.

So, I’ll still create a test case, but I was able to get it all working with renderData - populating a page title and populating collections.all, which was the primary issue.

@binyamin I’ll see what I can come up with. I’m using fully dynamic data sources that won’t be available from outside our internal netwek, so I’ll have to use dummy JSON and change a bunch to get it to be functional.