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
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.
Regarding the slug issue: I had to put the slug filter in front of my data. Sorry about that. Facepalm.
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.
It is! Iām going to close this as a duplicate of #481, which is coming very soon. Is that okay?
@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ā.
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!
Most helpful comment
renderDatastill 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!