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

Content generated from data in title and permalink issue #912

Closed
BregtDeLange opened this issue Feb 7, 2020 · 5 comments
Closed

Content generated from data in title and permalink issue #912

BregtDeLange opened this issue Feb 7, 2020 · 5 comments

Comments

@BregtDeLange
Copy link

BregtDeLange commented Feb 7, 2020

I have a detail page template, which gets its page content data from a JavaScript file that connects to a service. This works all fine, my pages get generated. However, I try to use the slug filter in the YAML section for the permalink, and I want to pass the title to the title field, to be used in my layout for <title>.

---
layout: page
tags: ["detail"]
pagination:
  data: products.results
  size: 1  
  alias: detail
  addAllPagesToCollections: true
renderData:
  title: {{detail.item.title}}
permalink: "detail/{{ detail.item.id }}/{{detail.item.title slug}}/"
title: "{{renderData.title}}"
---

I followed the description given by others for this issues, but I'm stuck here. I really can't figure this out. I get this in my title.
[object Object]

SOLVED: And I get this error when using the slug filter in permalink I know this error is coming from Handlebars, but it says "helperMissing".

TypeError: (((intermediate value)(intermediate value) && stack1.title) || container.hooks.helperMissing).call is not a function
[2]         at Object.eval [as main] (eval at createFunctionContext (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:266:23), <anonymous>:6:150)
[2]         at main (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\node_modules\handlebars\dist\cjs\handlebars\runtime.js:176:32)
[2]         at ret (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\node_modules\handlebars\dist\cjs\handlebars\runtime.js:179:12)
[2]         at ret (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:515:21)
[2]         at C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\Engines\Handlebars.js:61:14
[2]         at Template.render (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\TemplateContent.js:182:28)
[2]         at async Template._getLink (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\Template.js:103:26)
[2]         at async Template.getOutputLink (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\Template.js:133:16)
[2]         at async Pagination.getPageTemplates (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\Plugins\Pagination.js:242:25)
[2]         at async Template.getTemplates (C:\Projects\StaticSiteRepo\Static Site Repo\node_modules\@11ty\eleventy\src\Template.js:428:23)

The slug filter is by default loaded, right?

EXTRA: Is it also possible to link to these generated pages via an object? I know there's the collections.detail which I could use, but I seem not be able to access it in an other template except for a file in the root.

Thanks.

@BregtDeLange BregtDeLange changed the title Content generated from data in title and parmalink issues Content generated from data in title and permalink issue Feb 7, 2020
@BregtDeLange
Copy link
Author

Regarding the slug issue: I had to put the slug filter in front of my data. Sorry about that. Facepalm.

@BregtDeLange
Copy link
Author

BregtDeLange commented Feb 9, 2020

Okay, found out myself. Here's my solution. Took me a while. I know the renderData is not documented and read about the reason. Is there anything similarly coming up in a next version of Eleventy? WHen working with JavaScript data files, this is a must have.

---
layout: page
tags: ["detail"]
pagination:
  data: products.products.results
  size: 1  
  alias: detail
  addAllPagesToCollections: true
renderData:
  title: "{{detail.item.title}}"
  id: "{{detail.item.id}}"
permalink: "detail/{{ detail.item.id }}/{{slug detail.item.title}}/"
title: {{{this.renderData.title}}}
id: {{{this.renderData.id}}}
---

And to link to a generated page

{{#each @root.collections.detail}}
	{{#eq ../item.id this.data.renderData.id}}
	<a href="{{this.url}}">More info</a>
	{{/eq}}
{{/each}}

However the slug function doesn't solve complex characters. I have é and à in my titles, which I generated pages from, and linking this through the collections object (this.url), sometimes breaks the url.

@zachleat
Copy link
Member

It is! I’m going to close this as a duplicate of #481, which is coming very soon. Is that okay?

@zachleat zachleat added this to the Next Minor Version milestone Feb 19, 2020
@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Mar 5, 2020

@BregtDeLange Head's up!
If I got the news right, renderData is deprecated in 0.11. (Currently in beta).
So some changes will be needed to consume the new option of „computed data”.

@zachleat
Copy link
Member

renderData still works (and actually received bug fixes) in 0.11.0 but will probably go away in 1.0. Computed Data is the way to go in the future—thanks!

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

3 participants