简体   繁体   中英

Liquid Warning: Liquid syntax error: Expected end_of_string but found id in

i'm using this line of code

<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;">

but i'm getting a liquid error like this

Liquid Warning: Liquid syntax error: Expected end_of_string but found id in "{{ 'device1.png' | asset_path | magick:resize:549x395 magick:quality

Can you help me with the right syntax of this ?

Thanks in advance. Carlos Vieira

I ran into the same issue. It seems a newer version of Liquid doesn't expect the pipe. I was able to fix it by removing the pipe altogether. Here was my issue:

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

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

This page may help with proper liquid syntax http://jekyll.tips/jekyll-cheat-sheet/

I ran into a similar issue today with the following code:

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

The problem was an extra space in the word 'title_case' - because it was a space followed by an underscore, Shopify interpreted it as an id!

The right answer is:

First use this plugin:

    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)

then in image use

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

This would fix for sure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM