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
Copy file name to clipboardExpand all lines: README.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,31 @@ For a working example, [take a look at the `home` module here](https://github.co
102
102
103
103
## Data
104
104
105
-
All official 11ty methods to gather data from an API or otherwise, will work here. There are many great examples of how to do this in the official 11ty documentation, including the use of GraphQL: https://www.11ty.dev/docs/data-js/
105
+
All official 11ty methods to gather data from an API or otherwise, will work here. There are many great examples of how to do this in the official 11ty documentation, including the use of GraphQL: https://www.11ty.dev/docs/data-js/.
106
+
107
+
To define _global_ data, add either JSON, JS or TypeScript files to the `./src/data` folder. These will then be parsed by 11ty and added via the [data cascade](https://www.11ty.dev/docs/data-cascade/). You can access these directly in your `.11ty.ts*` files.
108
+
109
+
For example, if you were to add a `global.ts` file to `./src/data`, you would access this via a `global` property in your pages argument object:
110
+
111
+
```tsx
112
+
interfaceIProps {
113
+
global: {
114
+
title:string;
115
+
};
116
+
}
117
+
118
+
/*[...]*/
119
+
120
+
function Page({ global }:IProps) {
121
+
return (
122
+
<main>
123
+
<h1>{global.title}</h1>
124
+
</main>
125
+
);
126
+
}
127
+
```
128
+
129
+
To add local data, e.g data specific to a module, add an `.11tydata.ts` file within the relevant module folder. This will then be accessible in exactly the same way as shown above, but only for that page. For example, if you added `home.11tydata.ts` to `./src/modules/home`, your home page `11ty.ts` file would have access to the values held within that data file.
0 commit comments