Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a variable into a custom tag in Liquid?

Tags:

liquid

I have written a custom tag in liquid, and I'd like to pass a variable to it. Liquid tags will turn any parameter into a string.

For example:

{% nav page /some/url.html %}

Where page is a variable.

Is there a way to get Liquid to treat page as a variable and not a string?

Thanks in advance!

like image 932
Seth Ladd Avatar asked Oct 05 '11 18:10

Seth Ladd


1 Answers

To answer the general question and not the part specifically about the page variable, you can also pass the contents of the tag through the Liquid parser again:

def initialize(tag_name, markup, tokens)
  @markup = markup
  super
end

def render(context)
  content = Liquid::Template.parse(@markup).render context
end
like image 103
bwest Avatar answered Sep 28 '22 00:09

bwest