{"record":{"id":"ab28311155ff799b","repo":"Shopify/liquid","slug":"errors-syntax-capture","errorCode":"errors.syntax.capture","errorMessage":"options[:locale].t(\"errors.syntax.capture\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.syntax\\.capture\"\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/capture.rb","lineNumber":38,"sourceCode":"  # @liquid_syntax_keyword variable The name of the variable being created.\n  # @liquid_syntax_keyword value The value you want to assign to the variable.\n  class Capture < Block\n    include ParserSwitching\n\n    Syntax = /(#{VariableSignature}+)/o\n\n    attr_reader :to\n\n    def initialize(tag_name, markup, options)\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      else\n        raise SyntaxError, options[:locale].t(\"errors.syntax.capture\")\n      end\n    end\n\n    def strict_parse(markup)\n      lax_parse(markup)\n    end\n\n    def strict2_parse(markup)\n      p = @parse_context.new_parser(markup.strip)\n      @to = p.consume(:id)\n      p.consume(:end_of_string)\n    end\n\n    def render_to_output_buffer(context, output)\n      context.resource_limits.with_capture do\n        capture_output = render(context)\n        context.scopes.last[@to] = capture_output\n      end","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/capture.rb#L20-L56","documentation":"The `capture` tag stores rendered output into a variable, so its markup must match Capture::Syntax (a valid variable name). In lax_parse (also used by strict_parse), if the markup does not match, Liquid raises SyntaxError with the localized message 'errors.syntax.capture'. Parsing aborts before any rendering.","triggerScenarios":"{% capture %} with empty markup, or markup that is not a single variable name, e.g. `{% capture foo.bar = x %}` or `{% capture \"name\" %}`.","commonSituations":"Hand-edited theme templates; copying capture blocks and mangling the variable name; templates generated by string concatenation losing the variable argument; beginners writing `{% capture greeting %}Hello{% endcapture %}` variants with punctuation in the name.","solutions":["Give the capture tag exactly one variable name: {% capture greeting %}...{% endcapture %}","Remove '=' or dotted assignment targets from the capture markup; capture only takes a plain name","If you need assignment of an expression instead of block output, use {% assign var = expr %}","Lint templates before deploy to catch malformed capture tags"],"exampleFix":"// before\n{% capture \"headline\" %}{{ title | upcase }}{% endcapture %}\n// after\n{% capture headline %}{{ title | upcase }}{% endcapture %}","handlingStrategy":"validation","validationCode":"def valid_capture_markup?(markup)\n  markup =~ /\\A[\\w\\-\\.]+\\z/\nend","typeGuard":null,"tryCatchPattern":"begin\n  Liquid::Template.parse(source)\nrescue Liquid::SyntaxError => e\n  raise TemplateSyntaxError.new(source: source, cause: e)\nend","preventionTips":["Capture takes exactly one plain variable name — no quotes, '=' or assignments","Use assign for expression assignment, capture for block output","Lint templates before deployment"],"tags":["liquid","ruby","template-syntax","capture-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"}