class Liquid::Include
Include allows templates to relate with other templates
Simply include another template:
{% include 'product' %}
Include a template with a local variable:
{% include 'product' with products[0] %}
Include a template for a collection:
{% include 'product' for products %}
Constants
- Syntax
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Calls superclass method
# File lib/liquid/tags/include.rb, line 20 def initialize(tag_name, markup, options) super if markup =~ Syntax @template_name = $1 @variable_name = $3 @attributes = {} markup.scan(TagAttributes) do |key, value| @attributes[key] = value end else raise SyntaxError.new(options[:locale].t("errors.syntax.include".freeze)) end end
Public Instance Methods
parse(tokens)
click to toggle source
# File lib/liquid/tags/include.rb, line 38 def parse(tokens) end
render_with_profiling(context)
click to toggle source
# File lib/liquid/profiler/hooks.rb, line 14 def render_with_profiling(context) Profiler.profile_children(@template_name) do render_without_profiling(context) end end
Also aliased as: render
Private Instance Methods
load_cached_partial(context)
click to toggle source
# File lib/liquid/tags/include.rb, line 64 def load_cached_partial(context) cached_partials = context.registers[:cached_partials] || {} template_name = context[@template_name] if cached = cached_partials[template_name] return cached end source = read_template_from_file_system(context) partial = Liquid::Template.parse(source, pass_options) cached_partials[template_name] = partial context.registers[:cached_partials] = cached_partials partial end
pass_options()
click to toggle source
# File lib/liquid/tags/include.rb, line 92 def pass_options dont_pass = @options[:include_options_blacklist] return {locale: @options[:locale]} if dont_pass == true opts = @options.merge(included: true, include_options_blacklist: false) if dont_pass.is_a?(Array) dont_pass.each {|o| opts.delete(o)} end opts end
read_template_from_file_system(context)
click to toggle source
# File lib/liquid/tags/include.rb, line 78 def read_template_from_file_system(context) file_system = context.registers[:file_system] || Liquid::Template.file_system # make read_template_file call backwards-compatible. case file_system.method(:read_template_file).arity when 1 file_system.read_template_file(context[@template_name]) when 2 file_system.read_template_file(context[@template_name], context) else raise ArgumentError, "file_system.read_template_file expects two parameters: (template_name, context)" end end