<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Hay and needle question (Liquid)</title>
    <link>http://forums.shopify.com/categories/2/posts/20554</link>
    <language>en-us</language>
    <description>Feed for discussion topic Hay and needle question (Liquid)</description>
    <item>
      <title>Hay and needle question (Liquid)</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 19:27:17 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554</guid>
      <description>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:

&lt;code&gt;&lt;pre&gt;
{% assign hay = 'caroline' %}
{% assign needle = 'line' %}
&lt;/pre&gt;&lt;/code&gt;

How do I know if my needle is my hay ?

&lt;code&gt;&lt;pre&gt;
{% if hay contains needle %} 
&lt;/pre&gt;&lt;/code&gt;

... does not work of course.</description>
    </item>
    <item>
      <title>Christocracy commented</title>
      <author>Christocracy</author>
      <pubDate>Fri, 04 Jul 2008 21:23:24 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20557</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20557</guid>
      <description>&lt;p&gt;You could use javascript.&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;

{% assign hay = "caroline" %}
{% assign needle = "line" %}

&amp;lt;script type="text/javascript"&amp;gt;

var hay = "{{hay}}";
var needles = hay.match("{{needle}}");
alert('match: ' + needles[0]);

&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;&lt;/code&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 21:38:33 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20558</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20558</guid>
      <description>&lt;p&gt;The functionality I am getting at is very basic, so I&amp;#8217;d rather use Liquid for it, if possible.&lt;/p&gt;


	&lt;p&gt;I am trying to read the &lt;span class="caps"&gt;URL&lt;/span&gt; from within collection.liquid. The &lt;span class="caps"&gt;URL&lt;/span&gt; contains a tag filter.&lt;/p&gt;


	&lt;p&gt;Let me give you an example of such &lt;span class="caps"&gt;URL&lt;/span&gt;:&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://shop.myshopify.com/collections/playback-graphics/compilation"&gt;http://shop.myshopify.com/collections/playback-graphics/compilation&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;From within collection.liquid, I must determine if the last argument in the &lt;span class="caps"&gt;URL&lt;/span&gt; is &amp;#8216;compilation&amp;#8217; as the markup will be very different on that page in that&amp;#8217;s the case. &amp;#8216;compilation&amp;#8217; is a tag, it is the tag used to filter the collection.&lt;/p&gt;


	&lt;p&gt;The following will output /collections/playback-graphics:&lt;/p&gt;


	&lt;p&gt;{{ collection.url }}&lt;/p&gt;


	&lt;p&gt;So here&amp;#8217;s what I need to set as condition:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% capture myURL %}{{ collection.url }}/compilation{% endcapture %}
{% if myURL == 'collections/playback-graphics/compilation' %}
  &amp;lt;p&amp;gt;Hello, I am on a page where I show compilations.&amp;lt;/p&amp;gt;
{% endif %}
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;The problem with this is that my mid argument in the &lt;span class="caps"&gt;URL &lt;/span&gt;(&amp;#8216;playback-graphics&amp;#8217;) must be a wildcard. It could any number of 3 things for now. So the condition will be longer&amp;#8230;&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% capture myURL %}{{ collection.url }}/compilation{% endcapture %}
{% if myURL == '/collections/playback-graphics/compilation' or myURL == '/collections/effects-shots/compilation' or myURL ==  '/collections/miscellaneous/compilation' %}
  &amp;lt;p&amp;gt;Hello, I am on a page where I show compilations.&amp;lt;/p&amp;gt;
{% endif %}
&lt;/pre&gt;&lt;/code&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 22:00:20 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20561</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20561</guid>
      <description>&lt;p&gt;Christocracy, I sure will use JavaScript. (By the way I did not know we could use a method like .match on a JavaScript String&amp;#8230;). But I would rather not use it for functionality that can break the site if JavaScript is disabled, &lt;em&gt;if at all possible&lt;/em&gt;. Within reason. :-)&lt;/p&gt;


	&lt;p&gt;@ Anyone who stumbles over this&amp;#8230;&lt;/p&gt;


	&lt;p&gt;The capture tag is very handy. What it does is assign to a variable whatever comes between the opening and end tag.&lt;/p&gt;


	&lt;p&gt;Examples of use:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% capture myVariable1 %}Hello!{% endcapture %}
&amp;lt;p&amp;gt;{{ myVariable1 }}&amp;lt;/p&amp;gt;
{% capture myVariable2 %}Hello, the name of my store is {{ shop.name }}.{% endcapture %}
&amp;lt;p&amp;gt;{{ myVariable2 }}&amp;lt;/p&amp;gt;
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Will output&amp;#8230;&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
Hello!
Hello, the name of my store is myShop.
&lt;/pre&gt;&lt;/code&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 22:45:46 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20569</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20569</guid>
      <description>&lt;p&gt;NO! My solution does not work at all.&lt;/p&gt;


	&lt;p&gt;I still cannot read the &amp;#8216;active&amp;#8217; tag. The filter tag.&lt;/p&gt;


	&lt;p&gt;Oh my god..&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 22:47:10 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20570</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20570</guid>
      <description>&lt;p&gt;I really don&amp;#8217;t see a non-javascript solution for this.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 22:51:42 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20571</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20571</guid>
      <description>&lt;p&gt;For this hay:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
&amp;lt;a title="Show products matching tag comp-1" href="/collections/playback-graphics/comp-1"&amp;gt;&amp;lt;span class="active"&amp;gt;comp-1&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt; &amp;lt;a title="Show products matching tag compilation" href="/collections/playback-graphics/compilation"&amp;gt;compilation&amp;lt;/a&amp;gt; &amp;lt;a title="Show products matching tag space" href="/collections/playback-graphics/space"&amp;gt;space&amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;I may look for that needle:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
&amp;lt;span class="active"&amp;gt;comp-
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;That is &lt;span class="caps"&gt;SUPER&lt;/span&gt; ugly solution.&lt;/p&gt;


	&lt;p&gt;I just need to find the Liquid output that gives me the active tag/filter.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Fri, 04 Jul 2008 23:20:30 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20575</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20575</guid>
      <description>&lt;p&gt;Solution to the hay and needle problem: the use of &lt;em&gt;includes&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;Thank you, Tobi.&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% if whatever includes 'tobi' %} 
  hi tobias
{% endif %}
&lt;/pre&gt;&lt;/code&gt;</description>
    </item>
    <item>
      <title>HunkyBill commented</title>
      <author>HunkyBill</author>
      <pubDate>Sat, 05 Jul 2008 02:59:31 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20584</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20584</guid>
      <description>&lt;p&gt;Heya,&lt;/p&gt;


	&lt;p&gt;If you compare what you &lt;strong&gt;can&lt;/strong&gt;  do with Liquid, and what you &lt;strong&gt;can&lt;/strong&gt; do with Liquid in Shopify, you&amp;#8217;ll notice there is a gap in implementation&amp;#8230; odd eh&amp;#8230; wish it was not so&amp;#8230;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Christina commented</title>
      <author>Christina</author>
      <pubDate>Sat, 05 Jul 2008 19:15:46 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20591</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20591</guid>
      <description>&lt;p&gt;Hi Caroline,&lt;/p&gt;


	&lt;p&gt;Stimulating conversation you had there with yourself!&lt;/p&gt;


	&lt;p&gt;How about this (untested, but similar things have worked for me):&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% capture standard_display %}
    [all that dull un-needlelike html]
{% endcapture %}

{% if current_tags.size &amp;gt; 0 %}
    {% for link in linklists.needle.links %}
        {% if current_tags.first == link.title %}
            [that sharp needle code]
        {% else %}
            {{standard_display}}
        {% endif %}
    {% endfor %}
{% else %}
    {{standard_display}}
{% endif %}

&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;requires making a linklist called &amp;#8220;needle&amp;#8221;, which contains the titles of your exceptional code pages.&lt;/p&gt;


&lt;code&gt;current_tags&lt;/code&gt; is handy little thing; corresponds to segment 3 of the url&lt;/code&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Sat, 05 Jul 2008 21:08:29 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20598</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20598</guid>
      <description>&lt;blockquote&gt;current_tags is handy little thing; corresponds to segment 3 of the url &lt;/blockquote&gt;

	&lt;p&gt;No way! &amp;mdash; I thought. And then I added this simplified snippet to my collection.liquid template, and what do you know, it woooorks!&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
{% if current_tags.size &amp;gt; 0 %}
The tag slash filter here is: {{ current_tags.first }}
{% endif %}
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Searching the Shopify wiki turned up no result:&lt;br /&gt;&lt;a href="http://wiki.shopify.com/Special:Search?search=current_tags"&gt;http://wiki.shopify.com/Special:Search?search=current_tags&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;As I understand we can filter a collection (in the ur) with more than one tag, since current_tags is an array&amp;#8230;? I will check.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Christina commented</title>
      <author>Christina</author>
      <pubDate>Sat, 05 Jul 2008 21:58:29 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-20602</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-20602</guid>
      <description>&lt;p&gt;very welcome,&lt;br /&gt;i&amp;#8217;ve been around here for a while, and have done a lot of sleuthing and testing and toying.  a number of things i&amp;#8217;ve come across by pure chance/hardheadedness/playfulness are undocumented.  if i had oodles of time, i&amp;#8217;d write them up, but unfortunately, when playtime is up, i&amp;#8217;ve got to forage, so i just scatter code here and there.&lt;/p&gt;


	&lt;p&gt;as far as i know, you&amp;#8217;re now the second person to use &lt;code&gt;current_tags&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;have fun! :)&lt;/p&gt;


	&lt;p&gt;and yes, you can filter with any number of tags. current_tags IS an array.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;edited to add:&lt;/em&gt; &lt;a href="http://wiki.shopify.com/Link_to_add_tag"&gt;this link&lt;/a&gt; might interest you.&lt;/p&gt;</description>
    </item>
    <item>
      <title>renobird commented</title>
      <author>renobird</author>
      <pubDate>Mon, 16 Nov 2009 16:16:25 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-31076</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-31076</guid>
      <description>&lt;p&gt;Wow!&amp;nbsp; I can't believe that current_tags is basically undocumented. I was searching and searching for a way to do exactly what it does - and as luck would have it - I stumbled on this. Thanks for the heads up Christina (I realize this thread is old news - but it's still super useful).&amp;nbsp; ;)&lt;/p&gt;
&lt;p&gt;Are there other gems out there that we should know about?&lt;/p&gt;
&lt;p&gt;Current Status: Truce between head and desk.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Mon, 16 Nov 2009 18:21:27 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-31080</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-31080</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Wow!&amp;nbsp; I can't believe that current_tags is basically undocumented.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Duly noted.&lt;/p&gt;
&lt;p&gt;By the way, Christina was an amazing contributor here and was for a very long time. Wonderful woman.&lt;/p&gt;
&lt;p&gt;There is another undocumented gem:&lt;/p&gt;
&lt;pre&gt;{{ current_page }}&lt;/pre&gt;
&lt;p&gt;Not to be confused with paginate.current_page, current_page can be used outside of your 'paginator'.&lt;/p&gt;
&lt;p&gt;Scroll down to Dennis' comment (#25) here: &lt;a href="http://support.myshopify.com/discussions/feedback/4268-conditional-for-first-page-of-a-collection-think-collection-landing-page-here"&gt;http://support.myshopify.com/discussions/feedback/4268-conditional-for-first-page-of-a-collection-think-collection-landing-page-here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I will update the wiki today, and make sure I can provide a relevant example for each.&lt;/p&gt;
&lt;p&gt;By the way, anyone can update the wiki. You need to register first over there, is all.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Jamie commented</title>
      <author>Jamie</author>
      <pubDate>Mon, 16 Nov 2009 22:29:21 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-31090</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-31090</guid>
      <description>&lt;blockquote&gt;
&lt;pre&gt;{{ current_page }}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;I wouldn't get to gung-ho on this one yet. I am experiencing pagination bugs using this method and still trying to find a work-around for my work around. When using this in the form discussed the pagination page numbers are being doubled, and in some cases pagination beyond page 1 isn't printing any of the products it should be when it involves tags ie collections/my-collection/tag.&lt;/p&gt;
&lt;p&gt;{{ if current_page == 1 }} may yield 8 pages when in fact there are only 5 if based on the paginate for everything beyond page 1. Frustrating.&lt;/p&gt;
&lt;p&gt;Whatever you have 'offset' fails to be subtracted from the paginators first page. So in other words on page 1 it is paginating by the defined paginate for current_page == 1 and creating pages for that count per page, when you get to page two, you will find the pagination numbers that are not taken into account initially. Haven't found a work around to trick this into shape yet.&lt;/p&gt;</description>
    </item>
    <item>
      <title>renobird commented</title>
      <author>renobird</author>
      <pubDate>Tue, 17 Nov 2009 01:48:06 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/20554#comment-31098</link>
      <guid>http://forums.shopify.com/categories/2/posts/20554#comment-31098</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;By the way, Christina was an amazing contributor here and was for a very long time. Wonderful woman.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;No longer contributes here?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;By the way, anyone can update the wiki. You need to register first over there, is all.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Thanks for the heads up. :)&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
