liquid

How to pass Javascript api request result variables to shopify liquid variable

Deadly 提交于 2020-01-06 07:44:10
问题 I have a javascript that makes a api call and gets a json response. I need to pass this to my liquid template and iterate over it. How do i pass the result variable on get request to a shopify liquid variable.? Thanks..! 回答1: You cannot do that. Liquid is rendered Server Side... whereas your Javascript is considered to be client side coding. When you are rendering your Liquid, you can transfer Liquid into Javascript for use later, but not vice versa. Also, if you are getting JSON via an API

Multiple conditions in if statement (Liquid)

会有一股神秘感。 提交于 2020-01-06 05:47:09
问题 Is it possible to put multiple conditions inside a single if statement in Shopify Liquid? For example this is what I have: {% if product.type != "A" and product.type != "B" and product.type != "C" %} //do something {% endif %} The reason I'm wondering is because syntax highlighting stops after the first "and" operator , as if everything after that has incorrect syntax. 回答1: Your syntax is 100% valid and will work in Shopify {% if product.type != "A" and product.type != "B" and product.type !=

Filter Collection Items by page metadata

こ雲淡風輕ζ 提交于 2020-01-05 06:01:53
问题 Context I have a jekyll collection called product-categories in which each file has the following metadata in front matter: _product-categories/filename1.md --- - title - uuid --- I have a page whose front matter contains filenames from this collection (collection array selections are saved by their filenames with front matter)... page.html --- product-categories: - filename1 - filename2 --- [list of product-categories to be displayed here] Goal I want to display the title (from the

Filter Collection Items by page metadata

陌路散爱 提交于 2020-01-05 06:00:26
问题 Context I have a jekyll collection called product-categories in which each file has the following metadata in front matter: _product-categories/filename1.md --- - title - uuid --- I have a page whose front matter contains filenames from this collection (collection array selections are saved by their filenames with front matter)... page.html --- product-categories: - filename1 - filename2 --- [list of product-categories to be displayed here] Goal I want to display the title (from the

Shopify JSON array returning results but some empty results

北战南征 提交于 2020-01-05 05:01:41
问题 I am wanting to pull back only results that are available but it is returning in the json response null,null,null,result, result for example. Here is the code: {% capture results %} {% for item in search.results %} {% assign product = item %} {% if product.available == true %} { "title" : {{ product.title | json }}, "url" : {{ product.url | within: product.collections.last | json }}, "thumbnail": {{ product.featured_image.src | product_img_url: 'thumb' | json }}, "available": {{ product

Custom Liquid tag with two parameters

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 21:31:24
问题 How can I write/invoke a custom Liquid Tag with two parameters? Context: Jekyll 2.1.1 I have some pages that are presented as a tab set. My page front matter is allowed to define extra tabs for some pages, like this: --- blah: blah extra-tabs: - A page: a-page.md - Another page: other-page.md --- I can solve this thanks to Iterate over hashes in Liquid Templates. But ... I have an additional constraint: when rendering a-page.md, the tab displayed should look different (<li class="active">...)

Shopify: Using variables from {% schema %} in Javascript

旧街凉风 提交于 2020-01-03 06:02:26
问题 I have a custom section that uses the following schema: {% schema %} { "name": "Custom", "settings": [ { "type": "textarea", "id": "custom_text_product", "label": "Insert name of the product here", "default": "Product" }, { "type": "textarea", "id": "custom_text_msg", "label": "Custom text", "default": "Insert text here" } ] } {% endschema %} Basically what I want is to get the text from each textarea, manipulate via Javascript and then add it to the DOM. Via .liquid I would simply do {{

Can I use liquid tags in css to have jekyll use a different background image on a per-page basis?

我的梦境 提交于 2020-01-02 04:08:09
问题 I'm using Jekyll and Liquid to generate a static web site on GitHub pages. I have found a template from templated.co (this one, specifically) that I am using for the page's layout. I have Jekyll delivering the content properly, but I would like to use a different background image on each page (in place of the default that's there now) by using Liquid in the CSS. I have Jekyll/Liquid recognizing the CSS by adding an empty front matter section to style.css, but I cannot get the following line

Liquid: Can I get a random element from an Array?

旧城冷巷雨未停 提交于 2020-01-01 08:02:09
问题 I'm trying to pick a random element from an array -- is this possible using Liquid/Jekyll? I can create an array -- and access a given index ... but is there a way to "shuffle" the array and then select an index, and thus get a random element from the array? prefix: ["Foo", "Bar", "Baz"] --- {{ page.prefix[1] }} # outputs "Bar" 回答1: Liquid doesn't have a filter for picking a random element from an array or an integer interval. If you want Jekyll to do that, you would have to create an

Get the difference in days between two dates in Jekyll

风格不统一 提交于 2020-01-01 05:41:15
问题 I would like to get the difference in days between two dates in Jekyll. How can I achieve this? {% capture currentDate %}{{ site.time | date: '%Y-%m-%d' }}{% endcapture %} {{currentDate}} {% capture event_date %}{{ entry.date }}{% endcapture %} {% if event_date < currentDate %}Yes{% else %}No{% endif %} In the entry there is my YAML: --- title: ChartLine C3 type: charts description: Chart with round for prisma id: c3-1 date: 2015-07-18 --- 回答1: If all you want to do is know whether a date