11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://demo-base-blog.11ty.dev/
MIT License
1.24k stars 616 forks source link

stuck on including a markdown snippet in the footer #41

Closed francisbarton closed 4 years ago

francisbarton commented 5 years ago

I have just started using eleventy and am using this base-blog theme. Now trying to customise it. I am trying to do something that I thought would be very simple to do with the Nunjucks templates and Markdown files, but I am not getting it to work, yet.

What I want to do

Use a markdown snippet as the source file for some footer text, and get this converted to HTML and drawn into the page layout as it's rendered.

What I've tried

I have edited base.njk so that I have:

<main class="note {% if templateClass %} {{ templateClass }} {% endif %}">
  {{ content | safe }}
</main>

<footer>
  <div class="footer-content">
    {% include 'footer.md' %}
  </div>
</footer>

and then I have a file footer.md that is basically just markdown. I have tried adding front matter to the .md file to get it recognised, but it seems to make no difference.

Here's my current footer.md:

---
layout: layouts/base.njk
templateEngineOverride: md
---

made with [eleventy](11ty.io)

Originally I tried making the footer text a template in markdown, and calling this in using {{ content | safe }} as in the <main> section, but all this did was reproduce the main content in the footer, not the content of my footer template.

From the 11ty docs, it seems to me that there is no reason why this include should not be converted from markdown to HTML

What I get:

When the footer is rendered, it does not convert the Markdown to HTML - I just get raw markdown (the link is not created).

I can't work out what I doing wrong, and would be grateful for any help.

francisbarton commented 5 years ago

I'm going to try to write the footer as a paired shortcode.

francisbarton commented 5 years ago

I think if I understood the way in which {{ content | safe }} worked then I could work out how to do a similar thing with the footer text. But this is currently a mystery to me.

{{ content | safe }} obviously brings in content from the .md templates such as about/index.md. How can I get it so I can write something similar like {{ footer | safe }} within the same layout file (base.njk) that will convert and include a footer.md snippet? I haven't yet discovered what the content bit means and where this is defined.

zachleat commented 4 years ago

base.njk needs to be base.md if you want it to process markdown! Keep in mind the default markdown template engine is Liquid so make sure you change that to Nunjucks if you want to keep using Nunjucks syntax in the file.

See https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files

zachleat commented 4 years ago

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and I will reopen the issue. Thanks!