Class: Liquid::Include

### Home Classes Methods

### In Files

- lib/liquid/tags/include.rb

### Parent

Liquid::Tag

### Methods

- ::new
- #blank?
- #parse
- #render

### Class/Module Index

Quicksearch

- Liquid
- Liquid::ArgumentError
- Liquid::Assign
- Liquid::BlankFileSystem
- Liquid::Block
- Liquid::Break
- Liquid::BreakInterrupt
- Liquid::Capture
- Liquid::Case
- Liquid::Comment
- Liquid::Context
- Liquid::ContextError
- Liquid::Continue
- Liquid::ContinueInterrupt
- Liquid::Cycle
- Liquid::Decrement
- Liquid::Document
- Liquid::Drop
- Liquid::ElseCondition
- Liquid::Error
- Liquid::FileSystemError
- Liquid::FilterNotFound
- Liquid::For
- Liquid::I18n
- Liquid::I18n::TranslationError
- Liquid::If
- Liquid::Ifchanged
- Liquid::Include
- Liquid::Increment
- Liquid::Interrupt
- Liquid::Lexer
- Liquid::LocalFileSystem
- Liquid::MemoryError
- Liquid::Parser
- Liquid::Raw
- Liquid::StackLevelError
- Liquid::StandardError
- Liquid::StandardFilters
- Liquid::SyntaxError
- Liquid::TableRow
- Liquid::Tag
- Liquid::Template
- Liquid::Unless
- Liquid::Utils
- Liquid::Variable
- FalseClass
- LiquidView
- Module
- NilClass
- TrueClass

No matching classes.

# 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, tokens) click to toggle source

    # File lib/liquid/tags/include.rb, line 20
    def initialize(tag_name, markup, tokens)
      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"))
      end

      super
    end

### Public Instance Methods

blank?() click to toggle source

    # File lib/liquid/tags/include.rb, line 41
    def blank?
      false
    end

parse(tokens) click to toggle source

    # File lib/liquid/tags/include.rb, line 38
    def parse(tokens)
    end

render(context) click to toggle source

    # File lib/liquid/tags/include.rb, line 45
    def render(context)
      partial = load_cached_partial(context)
      variable = context[@variable_name || @template_name[1..-2]]

      context.stack do
        @attributes.each do |key, value|
          context[key] = context[value]
        end

        if variable.is_a?(Array)
          variable.collect do |var|
            context[@template_name[1..-2]] = var
            partial.render(context)
          end
        else
          context[@template_name[1..-2]] = variable
          partial.render(context)
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.