Eric Walsh
Eric Walsh

Reputation: 3085

Create a partial using rendered html (from markdown) in Jekyll

I am trying to create nested collections in Jekyll and render the nested ones as partials.

I have two collection types:

Currently I am running into issues rendering all the trails on an "areas page". I want an area to list all trails, all of which should be pre-rendered from markdown to html, per each trail's individual layout.

However when I try to include the trail.content and list it out, the trail text comes out as unrendered markdown (I'm left with unevaluated tags like {{page.title}}, etc).

{% for trail in site.trails %}
   {{trail.content}}<br />
{% endfor %}

Is there any way to treat a trail as a partial? I want to instead have access to the rendered HTML content so i can inject it directly into my page, somewhat like how rails does it!

{% for trail in site.trails %}
   {{trail.rendered_content}}<br />
{% endfor %}

Thanks!

Upvotes: 4

Views: 468

Answers (1)

David Jacquel
David Jacquel

Reputation: 52809

As I cannot see your code, I've made some assumptions.

If you've declared collections like this :

collections:
  area:
    output: true
  trails:

The area collection is processed first and trails collection second. So when you try to get trails content from area, you receive unprocessed code.

Now try to reverse your configuration to :

collections:
  trails:
  area:
    output: true

You get trails processed first, so, when you call trails from area you receive processed code.

Et hop !

Upvotes: 1

Related Questions