1

How do I use LiquidJS Layout Blocks in Eleventy?

 2 years ago
source link: https://stackoverflow.com/questions/68834347/how-do-i-use-liquidjs-layout-blocks-in-eleventy
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How do I use LiquidJS Layout Blocks in Eleventy?

Join Stack Overflow to learn, share knowledge, and build your career.

Asked 2 days ago
Active yesterday
Viewed 35 times

According to https://liquidjs.com/tags/layout.html#Blocks LiquidJS supports Layout Blocks I can call from my Layout Template.

My default template contains the {{content}} block.

When I attempt to add another block called "sidebar" with either the {% %} or {{ }} and define it in my .md file it does not render.

Does 11ty support layout blocks out of the box?

asked 2 days ago

So I got this to work, but it's a bit messy I think. While Googling, I found folks saying that with Nunjucks, they could get this to work ONLY if they didn't use the layout front matter but specifically told Nunjucks to load the layout (https://github.com/11ty/eleventy/issues/1467). So I tried something similar in Markdown (remember that Liquid is the default processor).

Here's test2.md:

---
title: Test
---

{% layout main %}

{% block content %}
## this is test
<p>
{{ title }}
</p>
{% endblock %}

{% block sidebar %}
my sidebar is awesome
{% endblock %}

Note that I had to wrap my main content as well. Then in my layout, I noticed that: {{ content }} no longer worked. Instead, I had to use this:

{% block content %}{% endblock %}
{{ content }}

This seemed safe in my quick testing, as other templates not using the defined content block seemed to work ok. Just... be cautious.

answered 2 days ago

Your Answer

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Email and Password

Post as a guest

Name
Email

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged eleventy ssg or ask your own question.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK