1

I'm using 11ty to build a simple static site and have structured my project into templates and content directories. The template strings in my Nunjuck .njk templates are not rendering values from their corresponding JSON content files — they remain empty.

Here's my project structure:

project-root/
├── templates/
│   ├── index.njk
│   ├── about.njk
├── content/
│   ├── index.json
│   ├── about.json
├── dist/
├── .eleventy.js
└── package.json

Content and corresponding template:

index.json

{
  "title": "My Website",
  "heading": "Welcome to my website"
}

index.njk

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{ title }}</title>
</head>
<body>
  <h1>{{ heading }}</h1>
  <p>...</p>
</body>
</html>

11ty config:

.eleventy.js

module.exports = function(eleventyConfig) {
  return {
    dir: {
      input: "templates",
      data: "content",
      output: "dist"
    }
  };
};

Problem

After running the build with npx @11ty/eleventy, the dist/index.html output contains empty template strings where {{ title }} and {{ heading }} should be rendered. The final HTML looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
</head>
<body>
  <h1></h1>
  <p>...</p>
</body>
</html>

Question

Why is 11ty failing to render the content from the JSON files into my templates? How can I properly configure my project to resolve this issue?

1
  • Reading the documentation it says you can use your data by referring to the file name of your JSON file. So in your case inside your index.njk you would probably need {{ index.title }} etc. Commented Feb 5 at 17:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.