7
votes

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>
...
1

1 Answers

5
votes

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