|
6d343944b054e645fcac060aed55ec80
|
Hay and needle question (Liquid)by Caroline Schnapp - Member - 07:27PM, Jul 04, 2008 |
|
I am trying to determine if a string of text contains a substring of text. How do I do this in Liquid? Just spent over an hour looking for the answer. Say I have 2 variables containing text: the variables hay and needle. For the sake of providing a working example, let’s say I assign text to these variables, like so:
How do I know if my needle is my hay ?
... does not work of course. ---
Caroline from http://11heavens.com |
|
|
You could use javascript.
---
Blog: http://www.extonrails.com
|
|
|
The functionality I am getting at is very basic, so I’d rather use Liquid for it, if possible. I am trying to read the URL from within collection.liquid. The URL contains a tag filter. Let me give you an example of such URL: http://shop.myshopify.com/collections/playback-graphics/compilation From within collection.liquid, I must determine if the last argument in the URL is ‘compilation’ as the markup will be very different on that page in that’s the case. ‘compilation’ is a tag, it is the tag used to filter the collection. The following will output /collections/playback-graphics: {{ collection.url }} So here’s what I need to set as condition:
The problem with this is that my mid argument in the URL (‘playback-graphics’) must be a wildcard. It could any number of 3 things for now. So the condition will be longer…
---
Caroline from http://11heavens.com — Last edited 10:42PM, Jul 04, 2008 |
|
|
Christocracy, I sure will use JavaScript. (By the way I did not know we could use a method like .match on a JavaScript String…). But I would rather not use it for functionality that can break the site if JavaScript is disabled, if at all possible. Within reason. :-) @ Anyone who stumbles over this… The capture tag is very handy. What it does is assign to a variable whatever comes between the opening and end tag. Examples of use:
Will output…
---
Caroline from http://11heavens.com
|
|
|
NO! My solution does not work at all. I still cannot read the ‘active’ tag. The filter tag. Oh my god.. ---
Caroline from http://11heavens.com
|
|
|
I really don’t see a non-javascript solution for this. ---
Caroline from http://11heavens.com
|
|
|
For this hay:
I may look for that needle:
That is SUPER ugly solution. I just need to find the Liquid output that gives me the active tag/filter. ---
Caroline from http://11heavens.com
|
|
|
Solution to the hay and needle problem: the use of includes. Thank you, Tobi.
---
Caroline from http://11heavens.com
|
|
|
Heya, If you compare what you can do with Liquid, and what you can do with Liquid in Shopify, you’ll notice there is a gap in implementation… odd eh… wish it was not so… ---
Implement the Logic.
|
|
|
Hi Caroline, Stimulating conversation you had there with yourself! How about this (untested, but similar things have worked for me):
requires making a linklist called “needle”, which contains the titles of your exceptional code pages. current_tags is handy little thing; corresponds to segment 3 of the url
— Last edited 07:22PM, Jul 05, 2008 |
|
current_tags is handy little thing; corresponds to segment 3 of the url No way! — I thought. And then I added this simplified snippet to my collection.liquid template, and what do you know, it woooorks!
Searching the Shopify wiki turned up no result: Thank you, I just had a major breaktrough thanks to you. My layout depends within collection.liquid upon the tag filter I get, a.k.a the current tag. As I understand we can filter a collection (in the ur) with more than one tag, since current_tags is an array…? I will check. ---
Caroline from http://11heavens.com
|
|
|
very welcome, as far as i know, you’re now the second person to use have fun! :) and yes, you can filter with any number of tags. current_tags IS an array. edited to add: this link might interest you. — Last edited 10:04PM, Jul 05, 2008 |
Christocracy
Member
09:23PM, Jul 04, 2008