Can pagination.data be used to reference original data source?
#2808
-
|
Hey everyone, I'm working on generating pages in multiple languages using 11ty's pagination feature. It loops over an array of objects (the key is language); and then I reference the alias to go and fetch specific phrases from the original data source. The below shows a reduced test-case. In practice, I'll be referencing the data source many times to pull in all the translated content per page. So I'd like to be able to either:
Is there a way to achieve this with Nunjucks and/or frontmatter (YAML or JS)? Example Page:---
layout: templates/base.njk
pagination:
data: folder.my_Data_File
size: 1
alias: lang
permalink: "example/{{pagination.data | slugify | replace('folder-', '') }}/{{ lang }}.html"
---
Test output 1: {{ folder.my_Data_File[lang].field1 }}<br/> {# Have to specify data source again; I'd like to just specify it once #}
Test output 2: {{ folder.my_Data_File[lang].field2 }}<br/>
Test output 3: {{ folder.my_Data_File[lang].field3 }}<br/>
Desired pseudo-code: {{ pagination.data[lang].field1 }} {# This naturally doesn't work, but is there some way to reference `pagination.data` for this purpose? #}Example Data:I'm actually feeding translations in via CSV, but below is the resulting format after {
"EN": {
"field1": "text1 [EN]",
"field2": "text2 [EN]",
"field3": "text3 [EN]"
},
"DE": {
"field1": "text1 [DE]",
"field2": "text2 [DE]",
"field3": "text3 [DE]"
},
"FR": {
"field1": "text1 [FR]",
"field2": "text2 [FR]",
"field3": "text3 [FR]"
},
"SV": {
"field1": "text1 [SV]",
"field2": "text2 [SV]",
"field3": "text3 [SV]"
}
}Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Solved.
Final Page:---
layout: templates/base.njk
pagination:
data: folder.my_Data_File
size: 1
alias: c
permalink: "example/{{pagination.data | slugify | replace('folder-', '') }}/{{ c.language }}.html"
---
Test output 1: {{ c.field1 }}<br/> {# Nice, short, and dynamic data-pointer (thanks to `pagination.alias`) #}
Test output 2: {{ c.field2 }}<br/>
Test output 3: {{ c.field3 }}<br/>Actual Data:{
"EN": {
"language": "EN"
"field1": "text1 [EN]",
"field2": "text2 [EN]",
"field3": "text3 [EN]"
},
"DE": {
"language": "DE"
"field1": "text1 [DE]",
"field2": "text2 [DE]",
"field3": "text3 [DE]"
},
"FR": {
"language": "FR"
"field1": "text1 [FR]",
"field2": "text2 [FR]",
"field3": "text3 [FR]"
},
"SV": {
"language": "SV"
"field1": "text1 [SV]",
"field2": "text2 [SV]",
"field3": "text3 [SV]"
}
} |
Beta Was this translation helpful? Give feedback.
Solved.
resolve: valuesoption; as suggested by @pdehaan in this thread.csv-parseoptions I'm using mean each language is present as both object-keys and nested-values in the resulting JSON (my snippet in last message is wrong); which makes things easier.Final Page:
Act…