Liquid outputs raw text and not markdown

Hi, I have this liquid code: {%for page in site.pages%} {%if page.main%} [{{page.title}}]({{page.url}}) {%endif%} {%endfor%}but the output is not this Python Encryptor but this what i get
Could someone help me?

Possibly the code isn’t in a Markdown file (.md, etc)? The Markdown link syntax would only be expanded in a Markdown file, not other formats (HTML, Text, etc).

Liquid is only parsed by Jekyll when the file has YAML front matter.
Add the following to the top of your .md, .html, .css, etc file.

---
# intentionally left blank
---

And as @chuckhoupt suggested, Markdown is only parsed in .md or .markdown files. If the extension is .html or something else it will spit it back out to you as originally written.

The problem is it is an .markdown file and it has a YAML front matter.
I uploaded the site to github so you can look at is.

The page

code

Great, thanks for the source code link. I think the problem is that the Markdown link is indented with tabs, which Markdown interprets as a code-block, so the link code is rendered as-is.

Below is a copy of your loop followed by output steps, with the tabs explicitly marked with ➡︎. By default, Liquid will leave all the white-space outside its tags, so the tabs will trigger a code-block:

{%for page in site.pages%}
➡︎	{%if page.main%}
➡︎	➡︎	[{{page.title}}]({{page.url}})
➡︎	{%endif%}
{%endfor%}

Intermediate Markdown output:

➡︎	
➡︎	➡︎	[Main Page Title](/main-page-url/)
➡︎	

Final HTML output:

<pre>
<code>
➡︎	[Main Page Title](/main-page-url/)
</code>
</pre>

To fix this, you could simple remove the tabs (note that you can’t just replace them with spaces, because 4-spaces also marks a code-block). Alternatively, you could use Liquid’s white-space controls to strip the tabs. For example (untested code):

{% for page in site.pages %}
➡︎	{%- if page.main -%}
➡︎	➡︎	[{{page.title}}]({{page.url}})
➡︎	{%- endif -%}
{% endfor %}

That would generate the following intermediate Markdown with no tabs and a single newline after the link (assuming just 1 main page):

[Main Page Title](/main-page-url/) 

Working with Liquid and Markdown is always a bit tricky because white-space is so significant in Markdown, and the intermediate Liquid-generated Markdown is hidden during the Jekyll compilation process.

Ok, that is wierd. When I did

{% for page in site.pages %}
➡︎	{%- if page.main -%}
➡︎	➡︎	[{{page.title}}]({{page.url}})
➡︎	{%- endif -%}
{% endfor %}

It didn’t work, nothing was there. But when I did

{% for page in site.pages %}
➡︎	{%- if page.main -%}
[{{page.title}}]({{page.url}})
➡︎	{%- endif -%}
{% endfor %}

It worked!
Thanks, now I know whitespaces are a bigger deal in markdown than I thought.

1 Like