mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 03:10:39 -07:00
Add find_own_variable method to look up internal context variables
This commit is contained in:
+12
-1
@@ -177,7 +177,18 @@ module Liquid
|
|||||||
variable = variable.to_liquid
|
variable = variable.to_liquid
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|
||||||
return variable
|
variable
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_own_variable(key)
|
||||||
|
index = @scopes.find_index { |s| s.has_key?(key) }
|
||||||
|
return unless index
|
||||||
|
|
||||||
|
scope = @scopes[index]
|
||||||
|
variable = lookup_and_evaluate(@scopes[index], key).to_liquid
|
||||||
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|
||||||
|
variable
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_and_evaluate(obj, key)
|
def lookup_and_evaluate(obj, key)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ module Liquid
|
|||||||
# Store our progress through the collection for the continue flag
|
# Store our progress through the collection for the continue flag
|
||||||
context.registers[:for][@name] = from + segment.length
|
context.registers[:for][@name] = from + segment.length
|
||||||
|
|
||||||
parent_loop = context.find_variable('forloop'.freeze)
|
parent_loop = context.find_own_variable('forloop'.freeze)
|
||||||
|
|
||||||
context.stack do
|
context.stack do
|
||||||
segment.each_with_index do |item, index|
|
segment.each_with_index do |item, index|
|
||||||
|
|||||||
Reference in New Issue
Block a user