Shopify/liquid · error · Liquid::SyntaxError

errors.syntax.assign

errors.syntax.assign

Error message

parse_context.locale.t('errors.syntax.assign')

What it means

Liquid's `assign` tag requires markup of the form `variable = expression`. When the markup does not match the Assign::Syntax regex in lib/liquid/tags/assign.rb, the tag constructor calls raise_syntax_error and raises Liquid::SyntaxError with the locale-keyed message 'errors.syntax.assign'. This is a template parse-time failure: the template never renders.

Solutions

  1. Add the '=' between variable name and value: {% assign total = cart.total_price %}
  2. Ensure the left-hand side is a plain variable name (letters/digits/underscores), not an expression or literal
  3. Render the template with error_mode :lax during migration to see localized error messages and fix offending tags
  4. Add template pre-validation in CI that parses all templates and fails on SyntaxError

Example fix

// before
{% assign cart_total %}
// after
{% assign cart_total = cart.total_price %}
Defensive patterns

Strategy: validation

Validate before calling

def valid_assign_markup?(markup)
  markup =~ /\A[\w\-\.]+\s*=\s*.+\z/
end
# call before rendering; if false, fix the assign tag in the template

Try / catch

begin
  template = Liquid::Template.parse(source)
rescue Liquid::SyntaxError => e
  logger.error("Liquid assign syntax: #{e.message}")
  render_fallback_template
end

Prevention

When it happens

Trigger: Writing {% assign %} with markup that fails the /(VariableSignature+)\s*=\s*(.*)/ pattern: no '=' sign ({% assign foo bar %}), empty markup ({% assign %}), or a left side that is not a valid variable signature.

Common situations: Typos like `{% assign total %}` missing '='; porting templates from other engines that use different assignment syntax (e.g. `{% set %}`); whitespace/formatting mistakes in dynamically generated templates; users editing theme templates by hand.

Related errors


AI-assisted analysis of Shopify/liquid@807d45a6b3 (2026-09-08). Data as JSON: /api/errors/962f28e3d5d318f9. Report an issue: GitHub.

Appendix: source

Thrown at lib/liquid/tags/assign.rb:27

  #   Creates a new variable.
  # @liquid_description
  #   You can create variables of any [basic type](/docs/api/liquid/basics#types), [object](/docs/api/liquid/objects), or object property.
  #
  #   > Caution:
  #   > Predefined Liquid objects can be overridden by variables with the same name.
  #   > To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.
  # @liquid_syntax
  #   {% assign variable_name = value %}
  # @liquid_syntax_keyword variable_name The name of the variable being created.
  # @liquid_syntax_keyword value The value you want to assign to the variable.
  class Assign < Tag
    include ParserSwitching

    Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/om

    # @api private
    def self.raise_syntax_error(parse_context)
      raise Liquid::SyntaxError, parse_context.locale.t('errors.syntax.assign')
    end

    attr_reader :to, :from

    def initialize(tag_name, markup, parse_context)
      super
      parse_with_selected_parser(markup)
    end

    def lax_parse(markup)
      if markup =~ Syntax
        @to   = Regexp.last_match(1)
        @from = Variable.new(Regexp.last_match(2), parse_context)
      else
        self.class.raise_syntax_error(parse_context)
      end
    end

View on GitHub (pinned to 807d45a6b3)