I am trying to install instant-articles.xml with jekyll-last-modified-at gem. When I bundle exec jekyll serve I get following warning.
Liquid Warning: Liquid syntax error (line 9): Expected end_of_string but found pipe in "post in site.posts | sort 'last_modified_at'" in instant-articles.xml
xml file is
---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>{{ site.name | xml_escape }}</title>
<link>{{ site.url }}</link>
<description>
{% if site.description %}{{ site.description | xml_escape }}{% endif %}
</description>
{% for post in site.posts | sort 'last_modified_at' %}
{% unless post.link %}
<item>
<title>{{ post.title | xml_escape }}</title>
<link>{{ site.url }}{{ post.url }}</link>
<content:encoded>
<![CDATA[
{{ post.content }}
]]>
</content:encoded>
<guid isPermaLink="false">{{ post.url }}</guid>
<description>
{% if post.excerpt %}
{{ post.excerpt | xml_escape }}
{% else %}
{{ post.description | xml_escape }}
{% endif %}
</description>
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
<modDate>{{ post.last_modified_at | date: "%a, %d %b %Y %H:%M:%S %z" }}</modDate>
<author></author>
</item>
{% endunless %}
{% endfor %}
</channel>
</rss>
Have you tried using assign
and applying the sort
to that array? Sorting a for
loop directly doesn’t generally work in my experience.
Try this instead:
{% assign posts = site.posts | sort 'last_modified_at' %}
{% for post in posts %}
...
{% endfor %}
Thanks @mmistakes , it seems to be working
Hi! I am facing an error in my code "Liquid syntax error (snippets/gp-product-related line 56): Expected end_of_string but found pipe in "count_product_main == limit and count_product_main | modulo: 5 != 0"" while the whole code is
{% for item in cart.items %}
{{ item.product.title }}
{% assign existed_handle = item.product.handle %}
{% assign related_product_handles = '' %}
{% for collection in item.product.collections %}
{% if collection.title != 'Home page'%}
{% assign current_collection = collections[collection.handle] %}
{% for productItem in current_collection.products %}
{% assign not_existed = true %}
{% if existed_handle == productItem.handle %}
{% assign not_existed = false %}
{% endif %}
{% if not_existed %}
{% assign relatedHandleArr = related_product_handles | split: ',' %}
{% unless relatedHandleArr contains productItem.handle %}
{% if related_product_handles != '' %}
{% assign related_product_handles = related_product_handles | append: ',' %}
{% endif %}
{% assign related_product_handles = related_product_handles | append: productItem.handle %}
{% endunless %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% if related_product_handles != '' %}
<div class="gp-related-products" id="gp-related-products">
<div class="related-title">
<h2>{{ 'products.product.related_products' | t }}</h2>
</div>
<div class="related-items">
{% assign count_product_main = 1 %}
{% assign related_product_handle_items = related_product_handles | split: ',' %}
{% assign limit = related_product_handle_items.size %}
{% if limit > 15 %}
{% assign limit = 15 %}
{% endif %}
<div class="product_items slick-related">
{% for related_product_handle in related_product_handle_items %}
{% if count_product_main <= limit %}
{% if count_product_main == 1 %}
<div class="related-product-row">
{% endif %}
<div class="product-item">
{% assign productItem = all_products[related_product_handle] %}
{% include 'gp-product-grid' with product: productItem %}
</div>
{% if count_product_main == limit and count_product_main | modulo: 5 != 0 %}
{% assign remaining_items = 5 | minus: (count_product_main | modulo: 5) %}
{% for i in (1..remaining_items) %}
<div class="product-item empty"></div>
{% endfor %}
{% endif %}
{% if count_product_main == limit or count_product_main | modulo: 5 == 0 %}
</div>
{% endif %}
{% assign count_product_main = count_product_main | plus: 1 %}
{% endif %}
{% endfor %}
</div>
</div>
</div>
{% endif %}
</div>
{% endfor %}
`
`
Can you suggest me solution?
pcouy
May 4, 2023, 10:11pm
5
I suggest replacing
{% if count_product_main == limit and count_product_main | modulo: 5 != 0 %}
with
{% assign tmp = count_product_main | modulo: 5 %}
{% if count_product_main == limit and tmp != 0 %}
1 Like
Thanks it seems to be working but now its displaying a new error Liquid syntax error (snippets/gp-product-related line 58): Expected dotdot but found pipe in "{{5 | minus: (count_product_main | modulo: 5) }}"
can you guide me with it?
1 Like
pcouy
May 5, 2023, 8:07pm
7
It’s the same kind of thing. Just refactor the code inside your parenthesis in an assign
liquid tag in the same way you fixed the previous problem.
1 Like
I am not good with ruby language if you could rewrite that line of code it would be very grateful.
pcouy
May 6, 2023, 8:38am
9
Well I’m glad when I can help and teach a few things, but it seems like you do not want to learn.
Asking me to fix your issue for you without even trying makes it look like you are just trying to get me to work for you for free.
If you need a professional dev for your website, go hire one. But please don’t spam the forum asking people to work for free when it’s clear you don’t want to put effort to learn how to do it yourself!
1 Like
rdyar
May 6, 2023, 4:22pm
10
musab99:
ruby language
its not ruby - it is Liquid - not that that makes it any easier if you don’t know either one.
I’m guessing you are trying to edit something that was built by someone else? is that person not around to help?
I have no idea what the context of what you are trying to do is but based on the other solution maybe try something like
{% assign countTemp = count_product_main | modulo: 5 %}
{{ 5 minus: countTemp }}
here is a link to some liquid docs, very easy to read/understand: Introduction – Liquid template language
In this example the first line has {% somecodehere %}
and that is for things that are not actually output into the html - like opening or closing an if statement, setting a variable etc. The 2nd line has {{ somecodehere }}
and that should actually be output into the html (difference being the % instead of a 2nd curly brace.
Thanks for your help I will try to it myself