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

Allow to return arbitary data from the computed data property #1031

Closed
dweidner opened this issue Mar 21, 2020 · 1 comment
Closed

Allow to return arbitary data from the computed data property #1031

dweidner opened this issue Mar 21, 2020 · 1 comment

Comments

@dweidner
Copy link

Is your feature request related to a problem? Please describe.
I was a bit surprised to find out, that it is only possible to return string values from the computed data property. I expected the new feature to apply the magic string substitution only to string values and to leave other data types alone. Here a short example what I tried to do:

// ./src/pages/pages.11tydata.js
module.exports = {
  layout: 'page',
  eleventyComputed: {
    isHomePage ({ slug }) {
      return slug === 'home';
    },
    slug ({ page, slug = null }) {
      return slug || page.fileSlug;
    },
    permalink ({ slug, isHomePage = false }) {
      return isHomePage ? '/' : `/${slug}/`;
    }
  }
};

Describe the solution you'd like
It would be great, if I could return any data type from the computed data functions not only string value. I could think of other use cases, where this might be helpful:

module.exports = {
  layout: 'page',
  eleventyComputed: {
    seo ({ page }) {
      return {
        title: '…',
        description: '…',
        author: '…'
      };
    }
  }
};

Describe alternatives you've considered
In my example it would be easy to move the condition into the permalink function directly, but then the boolean would not be available within the template files.

@zachleat zachleat added this to the Eleventy v0.11.0 milestone Apr 27, 2020
@zachleat
Copy link
Member

This will ship with 0.11.0 beta 4

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

2 participants