{"record":{"id":"0d773b6346c572ab","repo":"OrchardCMS/OrchardCore","slug":"an-implementation-of-liquidtemplatecontext-is-required-0d773b","errorCode":null,"errorMessage":"An implementation of 'LiquidTemplateContext' is required","messagePattern":"An implementation of 'LiquidTemplateContext' is required","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/HttpRequestValue.cs","lineNumber":75,"sourceCode":"            nameof(HttpRequest.Host) => new StringValue(request.Host.Value),\n            nameof(HttpRequest.IsHttps) => BooleanValue.Create(request.IsHttps),\n            nameof(HttpRequest.Scheme) => new StringValue(request.Scheme),\n            nameof(HttpRequest.Method) => new StringValue(request.Method),\n            nameof(HttpRequest.RouteValues) => new ObjectValue(new RouteValueDictionaryWrapper(request.RouteValues)),\n\n            // Provides correct escaping to reconstruct a request or redirect URI.\n            \"UriHost\" => new StringValue(request.Host.ToUriComponent(), encode: false),\n            \"UriPath\" => new StringValue(request.Path.ToUriComponent(), encode: false),\n            \"UriPathBase\" => new StringValue(request.PathBase.ToUriComponent(), encode: false),\n            \"UriQueryString\" => new StringValue(request.QueryString.ToUriComponent(), encode: false),\n            _ => ValueTask.FromResult<FluidValue>(NilValue.Instance)\n        };\n    }\n\n    private static HttpRequest GetHttpRequest(TemplateContext context)\n    {\n        var ctx = context as LiquidTemplateContext\n            ?? throw new InvalidOperationException($\"An implementation of '{nameof(LiquidTemplateContext)}' is required\");\n\n        var httpContext = ctx.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;\n\n        return httpContext.Request;\n    }\n}\n","sourceCodeStart":57,"sourceCodeEnd":82,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/HttpRequestValue.cs#L57-L82","documentation":"The `http_request` Liquid value obtains the current HttpRequest through LiquidTemplateContext.Services -> IHttpContextAccessor -> HttpContext.Request. Because the context must expose services, the same cast guard applies: a plain TemplateContext triggers this InvalidOperationException instead of a NullReference deeper in the pipeline.","triggerScenarios":"Evaluating `{{ request }}` or request members (query, form, headers, path) in a template rendered with a base TemplateContext rather than LiquidTemplateContext.","commonSituations":"Custom batch/email template renderers that build contexts manually; unit tests of Liquid templates with `new TemplateContext()`; direct FluidValue member calls outside the view pipeline.","solutions":["Render with LiquidTemplateContext so `Services` is available to resolve IHttpContextAccessor.","Use ILiquidTemplateManager or the Liquid view engine for all template rendering in Orchard.","Pass the needed request data into the template Model explicitly if rendering outside an HTTP scope."],"exampleFix":"// before\nvar context = new TemplateContext { Model = model };\nvar html = await template.RenderAsync(context);\n// after\nvar context = new LiquidTemplateContext(sp, memberAccessor) { Model = model };\nvar html = await template.RenderAsync(context);","handlingStrategy":"type-guard","validationCode":"if (context is not LiquidTemplateContext) throw new InvalidOperationException(\"request value requires a LiquidTemplateContext\");","typeGuard":"bool IsLiquidContext(TemplateContext ctx) => ctx is LiquidTemplateContext;","tryCatchPattern":"try { var html = await template.RenderAsync(ctx); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"LiquidTemplateContext\")) { /* rebuild context via ILiquidTemplateManager */ }","preventionTips":["Render request-dependent templates only within the HTTP pipeline.","Pass request data explicitly via the Model when rendering in background jobs.","Use a single shared rendering helper that always supplies LiquidTemplateContext."],"tags":["liquid","fluid","type-cast","orchardcore"],"backgroundTag":"type-mismatch","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"}