Getting an "Liquid Exception: Liquid syntax error" while using Jekyll

Viewed 3363

I run bundle exec jekyll serve --trace on Windows 10. I got the following console message:

D:\MyPorfolio\perrot.github.io>bundle exec jekyll serve
Configuration file: D:/MyPorfolio/perrot.github.io/_config.yml
            Source: D:/MyPorfolio/perrot.github.io
       Destination: D:/MyPorfolio/perrot.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
  Liquid Exception: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in 2018-09-14-Rendering a python dict in jinja2.markdown

jekyll 3.7.3 | Error: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]

Does anyone know how to fix that problem? Thanks in advance.

The file 2018-09-14-Rendering a python dict in jinja2.markdown content is:

---
layout: post
title:  "Rendering a python dict in jinja2"
date:   2018-09-14 00:01:57 +0800
categories: python jinja2
---

    ```python
    url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    ```
2 Answers

Liquid tries to process your source code, particularly the jinja2 control tags, for that you need to tell Liquid to avoid processing it with the raw tags:

{% highlight python %}
{% raw %}
   url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}

{% endraw %}
{% endhighlight %}
Related