【问题标题】:Liquid Warning: Liquid syntax error: Expected end_of_string but found id inLiquid 警告:Liquid 语法错误:预期 end_of_string 但在
【发布时间】:2016-08-19 14:04:59
【问题描述】:

我正在使用这行代码

<img data-animate="zoomIn" srcset="{{ 'device1.png' | asset_path | magick:resize:549x395 magick:quality:100 }} 1024w, {{ 'device1.png' | asset_path | magick:resize:280x201magick:quality:100 }} 640w" src="{{ 'device1.png' | asset_path | magick:resize:549x395 magick:quality:100 }}" alt="Mac" style="width: 100%; top: 0; left: 0;">

但我遇到了这样的液体错误

Liquid 警告:Liquid 语法错误:应为 end_of_string 但已找到 “{{'device1.png'|asset_path|magick:resize:549x395 魔法:质量

你能帮我正确的语法吗?

提前致谢。 卡洛斯·维埃拉

【问题讨论】:

  • 您解决了这个问题吗?遇到同样的问题。
  • 抱歉,还没有……多张图片出现同样的问题……
  • 我想我通过用 or 替换 | 解决了这个问题
  • 对不起,但问题是相同的“预期 end_of_string 但在“{{'device1.png'或asset_path或magick:resize:549x395”中找到了id

标签: syntax liquid


【解决方案1】:

我遇到了同样的问题。似乎更新版本的 Liquid 并不期望管道。我能够通过完全移除管道来修复它。这是我的问题:

错误:{% for post in site.posts | limit: 5 %}

固定:{% for post in site.posts limit: 5 %}

此页面可能有助于正确的流式语法http://jekyll.tips/jekyll-cheat-sheet/

【讨论】:

  • 谢谢,只需卸下管道,也适用于当前版本的液体
  • 我遇到了相反的问题,警告/错误是由缺少管道引起的,我通过添加管道修复了它。
【解决方案2】:

我今天遇到了类似的问题,代码如下:

{%- if title_case contains ' ' -%}
  {%- assign all_strings = title_case | split: ' ' -%}
  {%- assign the_string = '' -%}
  {%- for str in all_strings -%}
      {% assign new_string = str | capitalize %}
  {% assign the_string = the_string | append: new_string | append: ' ' %}
  {%- endfor -%}
  {%- assign title_case = the_string | strip-%}
{%- endif -%}
{{ title _case }}

问题是单词“title_case”中有一个额外的空格 - 因为它是一个空格后跟一个下划线,Shopify 将其解释为一个 id!

【讨论】:

    【解决方案3】:

    正确答案是:

    首先使用这个插件:

        require "jekyll-assets"
    
    class Jekyll::ImagePath < Jekyll::Assets::Liquid::Tag
    
      def initialize(tag, args, tokens)
        super("img", args, tokens)
      end
    
      private
      def build_html(args, sprockets, asset, path = get_path(sprockets, asset))
          path
      end
    
    end
    
    Liquid::Template.register_tag('image_path', Jekyll::ImagePath)
    

    然后在图片中使用

    src="{% image_path 'customize-template-image.png' magick:resize: 549x375 magick:quality:100 %}"
    

    这肯定会解决

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 2013-04-28
      相关资源
      最近更新 更多