liquid

Is there a “break” tag to escape a loop in Liquid?

旧街凉风 提交于 2019-11-29 09:03:29
How do I break out of loop in Liquid, mainly a for-loop? I've tried {% break %} , but that fails with There were errors saving your file: Unknown tag 'break' . I'm trying to achieve something like: var variants = []; {% for item in cart.items %} {% if item.product.handle == "handle-name" %} variants = {{item.product.variants | json}}; {% break %} // won't work {% endif %} {% endfor %} For future visitors. Above code does work in current Liquid (gem v2.5.1). 来源: https://stackoverflow.com/questions/8028229/is-there-a-break-tag-to-escape-a-loop-in-liquid

How to list files in a directory with Liquid?

二次信任 提交于 2019-11-28 23:58:29
问题 I'm trying to learn how to use Jekyll along with Bootstrap; while studying them, I decided that I'd like to have an image carousel on my homepage. Since I'm really lazy I don't want to hard-code the paths needed to display every image inside the layout, and I wouldn't either prefer to use an array to store the list of images. I was wondering if there's any tag that could ask Jekyll to do these two steps: Look inside a specific directory For each file you found in that directory, repeat a

Excluding page from Jekyll navigation bar

有些话、适合烂在心里 提交于 2019-11-28 23:23:05
I am setting up a basic Github-hosted Jekyll website (so minimal, I am not even bothering to change the default theme). I have a nested site with a small number of first-tier pages that I would like to appear in the navigation bar (i.e. the default mode of operation). I also have some second-tier pages that I would like to NOT junk up the navigation bar. While a multi-level navigation system would be nice, I'm trying to avoid using plugins. Therefore, I believe the simplest solution is to just exclude tier two pages from the navigation system entirely. Here's a hypothetical page structure

What are some good ways to implement breadcrumbs on a Jekyll site?

橙三吉。 提交于 2019-11-28 21:38:17
I'm aware that there are single-level breadcrumbs in http://raphinou.github.com/jekyll-base/ but I'm looking for some good ways to have breadcrumbs on a Jekyll site when directories get to a depth of four or five levels . (Yes, I'm well aware that Jekyll is primarily a blogging engine and that perhaps I shouldn't use it for a general purpose website, especially with many directory levels. I'm also aware of http://octopress.org but haven't found a suitable plugin.) Based heavily on http://forums.shopify.com/categories/2/posts/22172 I came up with the following Jekyll layout for breadcrumbs, a

Getting a specific item from a collection in Jekyll

♀尐吖头ヾ 提交于 2019-11-28 21:27:51
I'm rebuilding my company's current site in Jekyll and attempting to set up the structure around a content model using objects (files in a collection) that have attributes (key/value pairs in YAML front-matter). Simple conceptual stuff designed to demonstrate effective content modeling to my team. Anything on the site that gets reused becomes an object, with the type of object defined by the specific collection that contains its file. So, I have a "services" collection for services offered by the company, a "clients" collection, and a "people" collection with a file for each person. The

How to use multiple arguments in an if statement with Liquid

不打扰是莪最后的温柔 提交于 2019-11-28 20:06:47
I want to use an if statement in Liquid with multiple conditionals. Something like: {% if (include.featured == "true" and product.featured == "true") or (include.featured == "false" and product.featured == "false") %} Multiple conditionals don't seem to work. Have I got the syntax wrong or can Liquid not handle this sort of if statement? Unfortunately, Liquid has a poor implementation of boolean algebra. Using Liquid's operators and tags , here is a dirty way to achieve it: {% if include.featured == true and product.featured == true %} {% assign test = true %} {% endif %} {% if include

Convert string to integer in Shopify Liquid?

二次信任 提交于 2019-11-28 18:14:49
I just read this related answer: How can I convert a number to a string? - Shopify Design — Ecommerce University To convert a string to a number just add 0 to the variable: {% assign variablename = variablename | plus:0 %} Not super elegant but it works! Inelegant or not, the answer given there isn't working for me. What's the right way to do this? Are the Liquid docs really missing such basic answers or am I just not finding the right place to look? Using assign with a math filter is correct. See this thread on GitHub , and this blog post . Variables created through {% capture %} are strings

For loop, wrap every two posts in a div

烈酒焚心 提交于 2019-11-28 17:04:18
Basically, I am using Jekyll (which uses the Liquid templating language) and I am trying to write a for loop which wraps every two items in a div . This is my current loop: <div> {% for post in site.posts %} <a href="{{ post.url }}">{{ post.title }}</a> {% endfor %} </div> Which would output four posts like so: <div> <a href="#">Title</a> <a href="#">Title</a> <a href="#">Title</a> <a href="#">Title</a> </div> My desired output for four posts is: <div> <a href="#">Title</a> <a href="#">Title</a> </div> <div> <a href="#">Title</a> <a href="#">Title</a> </div> How can I accomplish this? I know I

Liquid templates: even/odd items in for loop

怎甘沉沦 提交于 2019-11-28 16:50:12
If I have a for loop in Liquid (using Jekyll), how can I target even (or odd) items only? I have tried: {% for item in site.posts %} {% if forloop.index % 2 == 1 %} but that doesn't seem to work. I have also tried: (forloop.index % 2) == 1 and: forloop.index - (forloop.index / 2 * 2) == 1 Alex Lande I think you'll want to use the cycle tag for this. For example: {% for post in site.categories.articles %} <article class="{% cycle 'odd', 'even' %}"></article> {% endfor %} If you want different HTML markup for each cycle: {% for item in site.posts %} {% capture thecycle %}{% cycle 'odd', 'even' %

List Subcategories in GitHub Pages

半城伤御伤魂 提交于 2019-11-28 03:44:43
问题 Edit: I've created a repository here that tests jibe's answer below. I just end up getting a blank page when I visit /animals , so any help is appreciated! This is a follow-up to this question: Hierarchical Categories in GitHub Pages In that question, I found out how to list the posts of a particular hierarchical category. Now I'm trying to figure out how to list the subcategories of a particular hierarchical category. I'm using Jekyll on GitHub pages, and I want to have hierarchical