0
votes

I have the following if statement in Jekyll:

  {%assign current = page.url | split: '/' %}
<ul>
<li>
   <a href="../product-type/index.html" 
   {% if current == "product-type" %} class="active-circle"{% endif %}>
  <div class="circle"></div>
   </a></li>
</ul>

UPDATE: Even if I go into the compiled HTML file and add the "active-circle" class manually, the CSS for that class does not show up in my browser, and the link doesn't have that class when I inspect the element!

This WAS working earlier (I just have some CSS that changes the background color of div class="circle"). After I changed my build destination to a specified folder, it stopped working. I've printed out what {{current}} is just to be sure, and it is indeed what I'm checking for. I've also tried adding just a test "if" statement elsewhere, and that doesn't work, either.

Is anything wrong with my if statement?! I've been staring at this for hours and have no idea what went wrong!!

1

1 Answers

1
votes

The split liquid filter always returns an array.

Try :

{% assign myArray = "/a/b/c/" | split: "/" %}
<p>{{ myArray }}</p>          ---> abc
<p>{{ myArray | inspect}}</p> ---> ["", "a", "b", "c"]

In your case, you have :

{% assign current = "/product-type/" | split:"/" %}
<p>{{current | inspect}}</p>      --> ["", "product-type"]
<p>{{current.last | inspect}}</p> --> "product-type"

Now you can compare with :

{% if current.last == "product-type" %}  --> true