Expose var substitution paradigm #2071

Closed
gjtorikian opened this Issue Feb 19, 2014 · 1 comment

Comments

Projects
None yet
3 participants
Member

gjtorikian commented Feb 19, 2014

I just want an excuse to use the word paradigm.

Suppose I have the following layout:

{% for post in site.pages %}
  <div class="{% special_tag attr=post.title %})">

post.title is literally passed to the special_tag. You can't wrap this text in { } blocks either.

It would be nice if Jekyll exposed a method like this that tags could inherit:

    # set it up such that variables, like `post.title`, are still processed
    def self.look_up(context, name)
      lookup = context

      name.split(".").each do |value|
        lookup = lookup[value]
      end

      lookup
    end

parkr added the Feature label Feb 19, 2014

parkr self-assigned this Feb 19, 2014

Owner

parkr commented Feb 21, 2014

👍 this is a sweet idea.

@parkr parkr added a commit that referenced this issue Apr 22, 2014

@parkr parkr Add Jekyll::Utils.lookup_variable
Fixes #2071.
60ba764

@parkr parkr added a commit that referenced this issue Apr 22, 2014

@parkr parkr Add Jekyll::LiquidExtensions.lookup_variable
To use, just include `Jekyll::LiquidExtensions` as you please:

```ruby
class SayHi < Liquid::Tag
  include Jekyll::LiquidExtensions

  def initialize(tag_name, markup, tokens)
    @markup = markup.strip
  end

  def render(context)
    "hi #{lookup_variable(context, @markup)}"
  end
end
```

Fixes #2071.
4de2be8

parkr closed this in #2253 Apr 22, 2014

jekyllbot locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.