Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Expose var substitution paradigm #2071

Closed
gjtorikian opened this Issue · 1 comment

2 participants

@gjtorikian
Collaborator

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 parkr added the Feature label
@parkr parkr self-assigned this
@parkr
Owner

:+1: this is a sweet idea.

@parkr parkr referenced this issue from a commit
@parkr parkr Add Jekyll::Utils.lookup_variable
Fixes #2071.
60ba764
@parkr parkr referenced this issue from a commit
@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 parkr closed this in #2253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.