2

I'm working with Nunjucks templates in Eleventy. The page layout consists of a main content area and an aside. I am able to use Markdown for the content but cannot find a way to use Markdown for the aside. It would seem that only one source can be Markdown; any other sources included in the template must be Nunjucks templates.

index.njk:

  <article>
    {{ content | safe }} 
  </article>
  <aside>
    {% include "aside.md" %}
  </aside>

aside.md:

# Aside.

Result:

<article>
<p>This is the content from the upstream Markdown.</p>
</article>
<aside>
# Aside.
</aside>

The aside is still raw Markdown. How can I include processed Markdown?

I'm new to all these technologies and have a feeling I am missing something basic.

  • There is a discussion of same problem in 11ty bug tracker, with some solutions proposed. https://github.com/11ty/eleventy/issues/658 – Lesha Ogonkov Jul 08 '20 at 12:07
  • 1
    @LeshaOgonkov That solved my problem. – Dave Gardner Jul 09 '20 at 05:58
  • Does this answer your question? [How do I incorporate Multiple Markdown files into a Nunjucks template with Eleventy?](https://stackoverflow.com/questions/63404330/how-do-i-incorporate-multiple-markdown-files-into-a-nunjucks-template-with-eleve) – Lesha Ogonkov Aug 18 '20 at 18:04

1 Answers1

0

Use includes or macros!

Includes have to be placed in a specific folder (_includes - you can override this folder name, or even have sub-folders):

    {% include 'partials/google-analytics.html' %}
    {% include 'partials/cookie-consent.html' %}
    {% include 'partials/post-sharing.html' %}

Or you can define a macro (they have to be imported, or be defined where you use them). The PRO for macros is that you can pass in parameters when you call them, they work as functions...

{% macro paginationLink(active, disabled, href, title) %}    
    <li class="page-item {% if active %} active {% elseif disabled %} disabled {% endif %}">
        {% if disabled %} 
            <span class="page-link">{{ title | safe }}</span>
        {% else %}
            <a class="page-link" href="{{ href | url }}">{{ title | safe }}</a>
        {% endif %}        
    </li>
{% endmacro %}

The macro ^ can then be easily called:

{{ paginationLink(false, isFirst, firstPageHref, '<i class="fas fa-angle-double-left"></i>') }}
baHI
  • 1,510
  • 15
  • 20