From c82dc2a1ec95ab55fa8082ee897493b93399ff74 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 18 Sep 2023 15:42:59 +0200 Subject: [PATCH] Add Input accessors for Liquid --- .../Elsa.Liquid/Handlers/ConfigureLiquidEngine.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/Elsa.Liquid/Handlers/ConfigureLiquidEngine.cs b/src/modules/Elsa.Liquid/Handlers/ConfigureLiquidEngine.cs index d47628c9d..74a7f5eb2 100644 --- a/src/modules/Elsa.Liquid/Handlers/ConfigureLiquidEngine.cs +++ b/src/modules/Elsa.Liquid/Handlers/ConfigureLiquidEngine.cs @@ -44,6 +44,7 @@ internal class ConfigureLiquidEngine : INotificationHandler((x, name) => x.GetValueAsync(name)); memberAccessStrategy.Register((x, name) => ((IDictionary)x!)[name]); memberAccessStrategy.Register("Variables", x => new LiquidPropertyAccessor(name => GetVariable(x, name, options))); + memberAccessStrategy.Register("Input", x => new LiquidPropertyAccessor(name => GetInput(x, name, options))); memberAccessStrategy.Register("CorrelationId", x => x.GetWorkflowExecutionContext().CorrelationId); if (_fluidOptions.AllowConfigurationAccess) @@ -68,6 +69,14 @@ internal class ConfigureLiquidEngine : INotificationHandler GetInput(ExpressionExecutionContext context, string key, TemplateOptions options) + { + var workflowExecutionContext = context.GetWorkflowExecutionContext(); + var input = workflowExecutionContext.Input.TryGetValue(key, out var value) ? value : default; + + return Task.FromResult(input == null ? NilValue.Instance : FluidValue.Create(value, options)); + } + private static object? GetVariableInScope(ExpressionExecutionContext context, string variableName) { var q = from variable in EnumerateVariablesInScope(context)