ruby-on-rails-3template-engineliquid

using Liquid variables inside of a liquid tag call


I made a custom link tag in Liquid and I am trying to be able to pass liquid variables into the call for that tag like so

{{ assign id = 'something' }} // this value is actual dynamic while looping through data 
{% link_to article: id, text: 'Click Me!' %} // my custom tag

However this results in the article parameter being passed in as 'id' instead of 'something' as per the assign statement above it.

Does anyone know how to pass variables into tag calls?


Solution

  • Doesn't look like this is possible, my solution was to just pass the variable name in to the tag and grab it out of the context the tag is being rendered in. Like so:

    {% for article in category.articles %}
      {% link_to variable: article, text: title %}
    {% endfor %}
    

    in my tag code (condensed):

    def render(context)
      uri = "article/#{context[@options[:variable]]['id']}"
      "<a href='#{uri}'>#{build_link_text context}</a>"
    end