liquid

Whitespace control in Shopify Liquid

[亡魂溺海] 提交于 2019-12-23 17:09:11
问题 Shopify recently added whitespace control to the Liquid templating language: https://help.shopify.com/themes/liquid/basics/whitespace You essentially add an hyphen in your tag syntax {{- -}} , {%- -%} to strip whitespace (html empty line) outputted by a tag. For example: {%- assign variable = "hello" -%} {{ variable }} Renders: hello Instead of: hello Is there a way to turns this on for all assign tags? and/or all specific control flow or iteration tags? 回答1: Indeed. You turn it on when you

Using liquid tags in YAML Front Matter variables

时光总嘲笑我的痴心妄想 提交于 2019-12-23 07:19:25
问题 Is it possible to use Liquid tags in YAML Front Matter variables? For example if test.html contains: --- variable: "Date: {% date: '%D' %}" --- {{ page.variable }} then Jekyll will generate the following HTML: Date: {% date: '%D' %} instead of something like: Date: 03/13/14 Basically I'd like the Liquid tags in the YAML Front Matter variables to be processed. 回答1: It sounds like you're trying to store a formatted date in a variable so you don't need to re-format the date each time you use it.

How to capture if current vendor is selected

一笑奈何 提交于 2019-12-23 04:50:13
问题 In my sidebar on the collection pages and index, I have listed all vendors with the code below. Now I want to add an .active class to the <li> when that particular vendor is selected. I want to do the same thing with a list of product types. How do I check which vendor is selected? I tried {% if collection.handle == vendor %} . But it returns null as it can only capture collections names. <ul class="nav"> {% for vendor in shop.vendors %} <li class="collection-container {% if collection.handle

Shopify Sort cart.items array using Liquid script

二次信任 提交于 2019-12-23 01:40:04
问题 I want to sort the cart.items array in the cart.liquid file. And then I can display the times in the table in my expected order. {% for item in cart.items sort_by:item.line_price %} <div class="row"> <div class="span12"> <h1>Your cart</h1> <form action="/cart" method="post" id="cartform"> <table> </table> </form> </div> </div> {% endfor %} But the code doesn't work since I can't use sort_by:item.line_price in for statement. How can I sort an array using built-in features? The other problem is

How does Jekyll use post.html to generate pages?

馋奶兔 提交于 2019-12-22 10:47:05
问题 I'm having some difficulty getting Jekyll to use a particular theme and I think there's something fundamental I'm missing about how {{ content }} works with posts. So, in a generic Jekyll site, index.html has a layout specified in its front matter. When the site is generated, the layout includes index.html as {{ content }} . It's kind of inverted, where the page specifies the layout and then the layout calls the page, but simple enough. Posts, on the other hand, are all generated via a file,

Date comparison Logic / in Liquid Template Filter

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:42:42
问题 I'm attempting to create a "Pre-Order" Like mechanic where certain elements of my Shopify Liquid Template only show if the current date is more or less than the date specified in a Metafield. As of current this is what I have including logic: <!-- Check Today is correct --> <p>Today: {{'now' | date: '%d-%m-%Y' }}</p> <!-- This is the Metafield Output as a String --> <p>Release Date: {{ product.metafields.Release-Date.preOrder }}</p> <!-- Assign Variable "today_date" to the current date --> {%

Jekyll, Liquid - Get all pages from category from page

被刻印的时光 ゝ 提交于 2019-12-22 07:20:11
问题 I have a question in Jekyll Liquid. I have layout, where I want to show pages from category. To show category I use page.categories variable. When I show in bracket {{page.categories}} is correct. but I don't know, how to pass to loop? {% for post in site.categories[page.categories] %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} {% for post in site.categories[{{page.categories}}] %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} Don't work. If I

Rails Form block in helper - How do i include “Protect from forgery”

≡放荡痞女 提交于 2019-12-21 20:46:29
问题 I'm trying to build a form block for my liquid theme language. I have based my approach on this answer. How ever the answer seems to be incomplete. The problem is that protect from forgery and some other methods are unavailable. Causing an error: Liquid error: undefined method `protect_against_forgery?' for # This is my code: class LiquidFormTag < Liquid::Block include ActionView::Context include ActionView::Helpers::FormHelper def initialize(tag_name, markup, tokens) super end def render

How to pass a variable into a custom tag in Liquid?

回眸只為那壹抹淺笑 提交于 2019-12-21 07:20:54
问题 I have written a custom tag in liquid, and I'd like to pass a variable to it. Liquid tags will turn any parameter into a string. For example: {% nav page /some/url.html %} Where page is a variable. Is there a way to get Liquid to treat page as a variable and not a string? Thanks in advance! 回答1: If you are using Jekyll specifically, you can access the page variable this way: def render(context) page_url = context.environments.first["page"]["url"] 回答2: I had a similar problem. I solved it by

How to pass {% captured %} variable from a view to the layout in Jekyll/Liquid?

五迷三道 提交于 2019-12-21 06:59:06
问题 I am trying to rebuild a blog in Jekyll and I have stubled upon a simple task. Provided I have the following set of templates: default.html: {{ head }} {{ content }} frontpage.html: --- layout: default --- {% capture head %} Frontpage {% end %} {{ content }} index.html: --- layout: frontpage --- Other stuff I was expecting that {% capture head %} would pass a variable to layout. But it seems only variables from the Front Matter are actually being passed as page.variable_name . Is there a way