{"record":{"id":"e360b7c5e7fc73e5","repo":"Shopify/liquid","slug":"errors-syntax-for-invalid-attribute","errorCode":"errors.syntax.for_invalid_attribute","errorMessage":"options[:locale].t(\"errors.syntax.for_invalid_attribute\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.syntax\\.for_invalid_attribute\"\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/for.rb","lineNumber":104,"sourceCode":"        raise SyntaxError, options[:locale].t(\"errors.syntax.for\")\n      end\n    end\n\n    def strict_parse(markup)\n      p = @parse_context.new_parser(markup)\n      @variable_name = p.consume(:id)\n      raise SyntaxError, options[:locale].t(\"errors.syntax.for_invalid_in\") unless p.id?('in')\n\n      collection_name  = p.expression\n      @collection_name = parse_expression(collection_name, safe: true)\n\n      @name     = \"#{@variable_name}-#{collection_name}\"\n      @reversed = p.id?('reversed')\n\n      while p.look(:comma) || p.look(:id)\n        p.consume?(:comma)\n        unless (attribute = p.id?('limit') || p.id?('offset'))\n          raise SyntaxError, options[:locale].t(\"errors.syntax.for_invalid_attribute\")\n        end\n        p.consume(:colon)\n        set_attribute(attribute, p.expression, safe: true)\n      end\n      p.consume(:end_of_string)\n    end\n\n    private\n\n    def strict2_parse(markup)\n      strict_parse(markup)\n    end\n\n    def collection_segment(context)\n      offsets = context.registers[:for] ||= {}\n\n      from = if @from == :continue\n        offsets[@name].to_i","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/for.rb#L86-L122","documentation":"Raised by strict_parse for {% for %} when an attribute after the collection is neither 'limit' nor 'offset'. Strict mode only permits limit: and offset: parameters, each followed by a colon and an expression.","triggerScenarios":"A for tag with a mistyped or unsupported parameter under the strict parser, e.g. {% for p in products by 2 %}, {% for p in products step: 2 %}, or {% for p in products limit 5 %} (missing colon).","commonSituations":"Porting templates from other template languages that use 'by'/'step' pagination keywords; typos like 'limt:' or 'offest:'; omitting the colon before the value in strict mode.","solutions":["Replace unsupported keywords with limit: or offset:, e.g. {% for p in products limit: 5 offset: 2 %}","Ensure a colon follows limit/offset: limit: 10 not limit 10","Correct spelling of limit/offset attributes"],"exampleFix":"// before\n{% for p in products by 2 %}...{% endfor %}\n// after\n{% for p in products limit: 5 offset: 2 %}...{% endfor %}","handlingStrategy":"validation","validationCode":"attrs = markup.scan(/(\\w+)\\s*:/).flatten\nbad = attrs - %w[limit offset reversed]\nraise Liquid::SyntaxError, \"invalid for attributes: #{bad.join(',')}\" unless bad.empty?","typeGuard":"def valid_for_attributes?(markup)\n  markup.to_s.scan(/(\\w+)\\s*:/).flatten.all? { |a| %w[limit offset].include?(a) }\nend","tryCatchPattern":"begin\n  Liquid::Template.parse(src, error_mode: :strict)\nrescue Liquid::SyntaxError => e\n  logger.error(\"Invalid for-tag attribute: #{e.message}\")\n  raise\nend","preventionTips":["Only limit: and offset: are valid for-tag parameters in strict mode","Always use a colon after limit/offset","Translate other engines' 'by'/'step' pagination to limit/offset before porting templates"],"tags":["ruby","liquid","strict-mode","template-syntax"],"backgroundTag":"template-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"}