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
Attributes
attributes[R]
template_name_expr[R]
variable_name_expr[R]
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Calls superclass method
# File lib/liquid/tags/include.rb, line 21 def initialize(tag_name, markup, options) super if markup =~ Syntax template_name = $1 variable_name = $3 @variable_name_expr = variable_name ? Expression.parse(variable_name) : nil @template_name_expr = Expression.parse(template_name) @attributes = {} markup.scan(TagAttributes) do |key, value| @attributes[key] = Expression.parse(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 42 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(context.evaluate(@template_name_expr).to_s) do render_without_profiling(context) end end
Also aliased as: render
Private Instance Methods
load_cached_partial(template_name, context)
click to toggle source
# File lib/liquid/tags/include.rb, line 89 def load_cached_partial(template_name, context) cached_partials = context.registers[:cached_partials] || {} if cached = cached_partials[template_name] return cached end source = read_template_from_file_system(context) begin parse_context.partial = true partial = Liquid::Template.parse(source, parse_context) ensure parse_context.partial = false end cached_partials[template_name] = partial context.registers[:cached_partials] = cached_partials partial end
read_template_from_file_system(context)
click to toggle source
# File lib/liquid/tags/include.rb, line 107 def read_template_from_file_system(context) file_system = context.registers[:file_system] || Liquid::Template.file_system file_system.read_template_file(context.evaluate(@template_name_expr)) end