ruby 获取“Liquid异常:使用Jekyll时出现“Liquid syntax error

pzfprimi  于 2023-04-11  发布在  Ruby
关注(0)|答案(2)|浏览(255)

当我在Windows 10上运行命令bundle exec jekyll serve --trace时,我收到以下错误:
液体例外:Liquid语法错误(第8行):“for循环”中的语法错误-有效语法:for [item] in [collection] in 2018-09-14-在jinja2.markdown jekyll 3.7.3中渲染Python字典|错误:Liquid语法错误(第8行):“for循环”中的语法错误-有效语法:在[集合]中的[项目]
有人知道如何解决这个问题吗?
文件2018-09-14-在jinja2.markdown中渲染python dict内容为:

---
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 %}
    ```
qmb5sa22

qmb5sa221#

Liquid会尝试处理你的源代码,特别是jinja2控件标签,你需要告诉Liquid避免使用raw标签处理它:

{% 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 %}
vq8itlhq

vq8itlhq2#

1 -{% raw %}标记是this postthis post中python代码解决方案的一部分。
2 -解的另一部分can be a bug in the way Jekyll manages excerpts
删除代码中的空行,它就会工作。

相关问题