gabrimo
gabrimo

Reputation: 73

How do I incorporate Multiple Markdown files into a Nunjucks template with Eleventy?

CONTEXT:

GOAL:

EXPECTED RESULT

Processed html page:

    <html>
      <body>
        <div>
          <p>Some content originating from a markdown file.</p>
        </div>
        <div>
          <p>Some content originating from another markdown file.</p>
        </div>
      </body>
    </html>

ATTEMPTED ACTIONS

Here is what I've tried so far...

(Note: I've excluded my base.njk (html doctype shell) for readability.)

1. NJK MAIN with NJK PARTIAL INCLUDES

INPUT

Directory Structure

src/
    /_includes
        base.njk
        _layout-A.njk
        _layout-B.njk
    main-layout.njk
    content-1.md
    content-2.md

main-layout.njk

    {% extends "base.njk" %}

    {% block content %}

        {% include '_layout-A.njk' %}

        {% include '_layout-B.njk' %}

    {% endblock %}

content-1.md

    ---
    layout: _layout-A.njk
    --- 
    Some content.

_layout-A.njk

    <div>{{ content | safe }}</div>

content-2.md

    ---
    layout: _layout-B.njk
    --- 

    Some more content.

_layout-B.njk

    <div>{{ content | safe }}</div>

RESULT

dist/
    /content-1
        index.html
    /content-2
        index.html
    /main-layout
        index.html

main-layout/index.html

    <html>
      <body>
        <div></div>
        <div></div> 
      </body>
    </html>


I'm at a loss for how the files are processed and what I can do to do what I set out to.

Upvotes: 5

Views: 2855

Answers (1)

Lesha Ogonkov
Lesha Ogonkov

Reputation: 1238

That's not how 11ty works. Each MD file is a single page.

If you want to include multiple MD files to page, you should add custom filter for 11ty, to render it to html.

See examples in this issue https://github.com/11ty/eleventy/issues/658

Upvotes: 4

Related Questions