{"record":{"id":"962f28e3d5d318f9","repo":"Shopify/liquid","slug":"errors-syntax-assign","errorCode":"errors.syntax.assign","errorMessage":"parse_context.locale.t('errors.syntax.assign')","messagePattern":"parse_context\\.locale\\.t\\('errors\\.syntax\\.assign'\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/assign.rb","lineNumber":27,"sourceCode":"  #   Creates a new variable.\n  # @liquid_description\n  #   You can create variables of any [basic type](/docs/api/liquid/basics#types), [object](/docs/api/liquid/objects), or object property.\n  #\n  #   > Caution:\n  #   > Predefined Liquid objects can be overridden by variables with the same name.\n  #   > To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.\n  # @liquid_syntax\n  #   {% assign variable_name = value %}\n  # @liquid_syntax_keyword variable_name The name of the variable being created.\n  # @liquid_syntax_keyword value The value you want to assign to the variable.\n  class Assign < Tag\n    include ParserSwitching\n\n    Syntax = /(#{VariableSignature}+)\\s*=\\s*(.*)\\s*/om\n\n    # @api private\n    def self.raise_syntax_error(parse_context)\n      raise Liquid::SyntaxError, parse_context.locale.t('errors.syntax.assign')\n    end\n\n    attr_reader :to, :from\n\n    def initialize(tag_name, markup, parse_context)\n      super\n      parse_with_selected_parser(markup)\n    end\n\n    def lax_parse(markup)\n      if markup =~ Syntax\n        @to   = Regexp.last_match(1)\n        @from = Variable.new(Regexp.last_match(2), parse_context)\n      else\n        self.class.raise_syntax_error(parse_context)\n      end\n    end\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/assign.rb#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the '=' between variable name and value: {% assign total = cart.total_price %}","Ensure the left-hand side is a plain variable name (letters/digits/underscores), not an expression or literal","Render the template with error_mode :lax during migration to see localized error messages and fix offending tags","Add template pre-validation in CI that parses all templates and fails on SyntaxError"],"exampleFix":"// before\n{% assign cart_total %}\n// after\n{% assign cart_total = cart.total_price %}","handlingStrategy":"validation","validationCode":"def valid_assign_markup?(markup)\n  markup =~ /\\A[\\w\\-\\.]+\\s*=\\s*.+\\z/\nend\n# call before rendering; if false, fix the assign tag in the template","typeGuard":null,"tryCatchPattern":"begin\n  template = Liquid::Template.parse(source)\nrescue Liquid::SyntaxError => e\n  logger.error(\"Liquid assign syntax: #{e.message}\")\n  render_fallback_template\nend","preventionTips":["Always write assign as `{% assign var = expression %}`","Run Liquid::Template.parse over all templates in CI","Use strict error_mode in development to surface issues early"],"tags":["liquid","ruby","template-syntax","assign-tag"],"backgroundTag":"liquid-tag-syntax-error","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}