How to use global data in eleventyComputed? #1828
Replies: 1 comment 5 replies
-
I might be a little confused here, but... ---
# src/pages/home.liquid
layout: layouts/home.html
eleventyComputed:
title: "{{ home.pageTitle.pt }}"
---
title=<pre>{{ title }}</pre> And my global ./src/_data/home.js data file: module.exports = {
pageTitle: {
pt: "PT PAGE TITLE",
},
}; And finally a ./src/_includes/layouts/home.html layout file: <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
</head>
<body>
<main>{{ content }}</p>
</body>
</html> The final rendered HTML page looks like this, so I think it's successfully pulling from my global data file via <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PT PAGE TITLE</title>
</head>
<body>
<main>
title=<pre>PT PAGE TITLE</pre>
</p>
</body>
</html> But all of this is hardcoded in a very basic sample repo, so I'm not sure how your CMS is creating files or the layout of your global data files or if there are additional include files of include files, etc. so it might not match your setup exactly. But if you have a public repo somewhere, I can take a look. |
Beta Was this translation helpful? Give feedback.
-
I might not understand correctly how to use the eleventyComputed property.
I created a layout to be used by all my pages. The regular data flows alright, and I am also able to set some variables from the partials to the layout via front-matter:
My issue starts with the <title> of the pages, inside the head of this layout. I cannot simply pass the value as a string via front-matter, because each page gets it's title from the CMS.
So I tried passing the data value from global data with no success:
This literally outputs: {{ home.pageTitle.pt }} as a string; and
outputs: {"[object Object]":null}
I don't know what any other way can I do this? It does look like a very simple scenario. Any help is very appreciated, thanks!
Beta Was this translation helpful? Give feedback.
All reactions