Module: Bridgetown::LiquidExtensions

Included in:
Tags::Find
Defined in:
bridgetown-core/lib/bridgetown-core/liquid_extensions.rb

Instance Method Summary collapse

Instance Method Details

#lookup_variable(context, variable) ⇒ Object

Lookup a Liquid variable in the given context.

Parameters:

  • context (Liquid::Context)
  • variable (String)

    the variable name

Returns:

  • (Object)

    value of the variable in the context or the variable name if not found



10
11
12
13
14
15
16
17
18
# File 'bridgetown-core/lib/bridgetown-core/liquid_extensions.rb', line 10

def lookup_variable(context, variable)
  lookup = context

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

  lookup || variable
end