11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.09k stars 494 forks source link

Cannot get markdown data in partial njk file which is included in a page? #1374

Open surjithctly opened 4 years ago

surjithctly commented 4 years ago

Hello All,

First time trying with 11ty.

Here's my problem:

I have home page called index.njk which uses default layout. Inside default, I have included navbar.njk Now inside navbar, I have created a hero block. And the hero block is overwritten by index.njk using include hero.njk

I want content for hero.njk from a markdown file. But Its not working, I have added a header.md file and added hero.njk as layout but its not working. Its blank. Eleventy also not giving any error.

So how do I add a markdown file. So I can

Call it in > hero.njk which is included in > index.njk which is using > default.njk where navbar is included > navbar.njk where hero block is defined

Screenshots for better understanding image

image

image

image

image

binyamin commented 4 years ago

@surjithctly I'm sorry you encountered this on your first run with Eleventy. I'm not familiar with Nunjucks, but I'll still try to replicate your issue.

surjithctly commented 4 years ago

@binyamin My guess is its not depend on the nunjucks, so by following this format, you may try using any other language.

Thanks for the reply.

As a workaround, I'm now calling data from _data/*.json

Essentially, My question is: How to get *.md data inside an included partial in Eleventy?

binyamin commented 4 years ago

Ah. Why can't you just {% import %} it?

surjithctly commented 4 years ago

@binyamin can you show an example? Sorry, I'm new to this.

pdehaan commented 4 years ago

Not sure if you can just {% import %} a raw markdown file into a liquid/markdown file (I imagine it would just output the raw Markdown and not parse it like you might expect). You might need to create some custom "markdown" filter. https://github.com/11ty/eleventy/issues/658 should have some good tips (although not sure if it will work with includes of includes of blocks of layouts since there are lots of moving pieces here.

Do you have this in a public repo somewhere? I can try taking a look, but this is a lot of files and typing from screenshots.

surjithctly commented 4 years ago

@pdehaan I have created a minimal repo on Codesandbox. You will be able to see the issue yourself.

Link: https://codesandbox.io/s/eleventy-include-bug-s98jr

Problem: As you can see, I have rendeded header and footer in index by including it. But I cannot get data from header.md and footer.md