1
votes

In Jekyll, I am trying to include a paragraph of "site information" that should go on a certain amount of pages in my website. The file structure of the certain information I am dealing with is a "team"folder->"_posts"folder-> then within the "_posts" folder is "site_information.md" and many other markdown files of pages that I want to include the "site_information.md" in. I do not want to use an includes statement on every single file in "_posts" folder if possible, so I want to make an includes statement in the "layout.html" file.

Here is what I have tried in the "layout.html" file:

{% if page.page == "page" %}
  {% include_relative site_information.md %}
  {{content}}
{% endif %}}

The code above included the information I wanted, but it did not include it in markdown format.

I then tried this:

{% if page.page == "page" %}
  {% capture site_info %}{% include_relative site_information.md %}{% endcapture %}
  {{site_info}}
  {{content}}
{% endif %}

This code does not display the "site_information.md" information on the pages at all when using the capture tag.

I then tried this:

{% if page.page == "page" %}
  {% capture site_info %}{% include_relative site_information.md %}{% endcapture %}
  {{site_info | markdownify}}
  {{content}}
{% endif %}

This code gave me the error when using the markdownify tag:
Liquid Exception: undefined method `gsub' for nil:NilClass in _layouts/layout.html

Does anyone know how to fix this so I can use an includes statement in the layout to properly display a markdownified file on a number of web pages?

1
Do I understand that you want to be able to add this site information conditionally on any page or post in your site with the test {% if page.page == "page" %}?David Jacquel
Yes, that is correct.Healy Fuess
But a relative include cannot be relative to index.html and to post/123456-mypost.md. Why not an include with the same test ?David Jacquel
Using a regular include tag, the site information was displayed on the page I wanted, but it was not in markdown format. Then I used a capture tag with the same includes statement with a markdown tag as well, and that is when I start to get the error: Liquid Exception: undefined method `gsub' for nil:NilClass in _layouts/layout.htmlHealy Fuess
did you have github repository?David Jacquel

1 Answers

0
votes

Check that you are not trying to apply the markdownify filter to empty text. You will get Liquid Exception: undefined method 'gsub' for nil:NilClass if there is no text to markdownify.

Since you say that

This code does not display the "site_information.md" information on the pages at all when using the capture tag.

using the capture method while it does not import any text will likely cause an error.