{"record":{"id":"c7b831ce1dbaca03","repo":"OrchardCMS/OrchardCore","slug":"page-title-tag-requires-a-segment-argument","errorCode":null,"errorMessage":"page_title tag requires a segment argument","messagePattern":"page_title tag requires a segment argument","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/PageTitleSegmentsTags.cs","lineNumber":41,"sourceCode":"        return Completion.Normal;\n    }\n\n    public static async ValueTask<Completion> WriteAddSegmentAsync(IReadOnlyList<FilterArgument> argumentsList, TextWriter _1, TextEncoder _2, TemplateContext context)\n    {\n        var arguments = new NamedExpressionList(argumentsList);\n\n        await AddSegmentInternalAsync(arguments, context);\n\n        return Completion.Normal;\n    }\n\n    private static async Task<IPageTitleBuilder> AddSegmentInternalAsync(NamedExpressionList arguments, TemplateContext context)\n    {\n        var services = ((LiquidTemplateContext)context).Services;\n\n        var titleBuilder = services.GetRequiredService<IPageTitleBuilder>();\n\n        var segmentExpression = arguments[\"segment\", 0] ?? throw new ArgumentException(\"page_title tag requires a segment argument\");\n        var segment = (await segmentExpression.EvaluateAsync(context)).ToStringValue();\n\n        var positionExpression = arguments[\"position\", 1];\n        var position = positionExpression == null ? \"0\" : (await positionExpression.EvaluateAsync(context)).ToStringValue();\n\n        titleBuilder.AddSegment(new HtmlString(segment), position);\n\n        return titleBuilder;\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":52,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/PageTitleSegmentsTags.cs#L23-L52","documentation":"The Liquid `page_title add_segment` tag requires a `segment` argument (the first positional argument or a named `segment:`) because it is the text added to the page title. When `arguments[\"segment\", 0]` resolves to null — no positional or named segment supplied — the tag throws an ArgumentException with this message.","triggerScenarios":"Calling `{% page_title %}` with the add-segment style but omitting the segment, e.g. `{% page_title position:'2' %}` with no segment value, or `{% page_title add_segment:true %}` without `segment:`.","commonSituations":"Copy-pasted title-tag snippets with arguments stripped; a Liquid variable used as the segment that is null/undefined so the named argument lookup misses; typos like `segments:` instead of `segment:`.","solutions":["Pass the segment as the first positional argument: `{% page_title 'My Section' %}`.","Or use the named form: `{% page_title segment:'My Section', position:'2' %}`.","If the segment comes from a variable, ensure the variable is assigned and non-null before the tag executes."],"exampleFix":"// before\n{% page_title position:'2' %}\n// after\n{% page_title 'My Section', position:'2' %}","handlingStrategy":"validation","validationCode":"{% if segment == blank %}{% // page_title add_segment requires a non-empty segment %}{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the segment as first positional argument or `segment:'...'`.","Guard dynamic segment variables for null/blank before the tag.","Watch for typos (`segments:` is not `segment:`)."],"tags":["liquid","razor-tags","missing-argument","orchardcore"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}