You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering how I would map data objects from a global data directory to individual templates, without namespacing them.
For example, one.json, two.json, and three.json live in the _data global data directory. In the content templates directory I have one.hbs, two.hbs, and three.hbs. So the properties of one.json should be inherited by one.hbs, two.json should be inherited by two.hbs, and so on.
From what I can tell, I can do this with an 11tydata.js file for each template file (e.g. one.11tydata.js for one.hbs, and two.11tydata.js for two.hbs, etc), but I'm trying to avoid redundancy and have a single 11tydata.js file for the entire templates directory. I've looked into using computed data but I still end up with data being namespaced for each template (e.g. one.hbs has to access one.json via one.someProp instead of just someProp). Within the templates I would prefer to not have the [data].json properties name spaced and have to access the JSON properties like one.propA, one.propB, etc. Instead I want to be able to reference the properties like propA, propB, etc. from the one.json file within one.hbs template.
For more context I'm working on adding i18n to a site and have a bunch of locales JSON files, where each locale file maps to a specific page (one.json maps to one.html), but I have multiple locales for each language (e.g. one-en.json, two-es.json, three-zh.json). So my templates directory is set up as content/en/[page].hbs, content/es/[page].hbs, etc. My goal is to use the same layout for each page and pass that layout the correct locale so that I avoid writing the same markup for each page in en/, es/, and zh/.
Any suggestions or examples would be appreciated, thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm wondering how I would map data objects from a global data directory to individual templates, without namespacing them.
For example,
one.json
,two.json
, andthree.json
live in the_data
global data directory. In thecontent
templates directory I haveone.hbs
,two.hbs
, andthree.hbs
. So the properties ofone.json
should be inherited byone.hbs
,two.json
should be inherited bytwo.hbs
, and so on.From what I can tell, I can do this with an
11tydata.js
file for each template file (e.g.one.11tydata.js
forone.hbs
, andtwo.11tydata.js
fortwo.hbs
, etc), but I'm trying to avoid redundancy and have a single11tydata.js
file for the entire templates directory. I've looked into using computed data but I still end up with data being namespaced for each template (e.g.one.hbs
has to accessone.json
viaone.someProp
instead of justsomeProp
). Within the templates I would prefer to not have the[data].json
properties name spaced and have to access the JSON properties likeone.propA
,one.propB
, etc. Instead I want to be able to reference the properties likepropA
,propB
, etc. from theone.json
file withinone.hbs
template.For more context I'm working on adding i18n to a site and have a bunch of locales JSON files, where each locale file maps to a specific page (
one.json
maps toone.html
), but I have multiple locales for each language (e.g.one-en.json
,two-es.json
,three-zh.json
). So my templates directory is set up ascontent/en/[page].hbs
,content/es/[page].hbs
, etc. My goal is to use the same layout for each page and pass that layout the correct locale so that I avoid writing the same markup for each page inen/
,es/
, andzh/
.Any suggestions or examples would be appreciated, thanks!
Beta Was this translation helpful? Give feedback.
All reactions