Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll - Pass a jekyll variable to a custom liquid tag

I'm trying to work out how to pass a Jekyll variable to a liquid tag plugin. I tried doing this:

{% liquidtag {{ variable }} %}

But the variable does not get realised and the tag just receives the variable name with the curly brackets: {{ variable }}

It also does not get realised when I use: {% liquidtag {% variable %} %} - the {% before the variable gets included in the string and the %} after the variable gets matched with the first {% of the liquid tag - the last closing %} get's ignored. I.e, this gets passed: {% variable

What I want is for the actual value of the variable to be passed to the tag.

Here's the tag:

class CatAbs < Liquid::Tag
        def initialize(tag_name, text, tokens)
          super
          @text = text
          puts @text
        end
        def render(context)
          return @text.split("-").at(1)
        end
      end

And here's how I'm currently referencing the tag:

{% for tag in site.categories %} 
<div class="grid grid-pad">
  <a><h2>{% CatAbs {{ tag[0] }} %} »</h2></a>
...
like image 996
Pozogo Avatar asked Mar 20 '16 15:03

Pozogo


1 Answers

After a lot of searching, I finally found the answer. I don't know why it was so difficult for me to find before! Sorry for the duplicate question!
Here's the answer I found:

using Liquid variables inside of a liquid tag call

like image 75
Pozogo Avatar answered Nov 16 '22 03:11

Pozogo