Skip to content

Conversation

gvkries
Copy link
Contributor

@gvkries gvkries commented Sep 23, 2025

This pull request adds support for handling StringValues in Liquid templates within OrchardCore, allowing for more natural manipulation and comparison of HTTP query, header, and form values that may be multi-valued. It introduces a new StringValuesValue Fluid value type, updates the template options configuration to use it, and adds comprehensive unit tests to ensure correct behavior and compatibility with Liquid operations.

Core functionality:

  • Added a new StringValuesValue class implementing FluidValue, enabling proper handling of StringValues (multi-valued strings) in Liquid templates, including comparison, indexing, iteration, and property access like size, first, and last.
  • Updated TemplateOptionsConfigurations.cs to wrap StringValues in StringValuesValue and to register member access strategies for QueryCollection and HeaderDictionaryWrapper using StringValues, ensuring these HTTP-related values are exposed correctly to Liquid templates. [1] [2] [3]

Testing and validation:

  • Added extensive unit tests in LiquidTests.cs to verify StringValuesValue behaviors, including string comparison, array operations (iteration, indexing), property access, containment checks, boolean conversion, and handling of empty values. [1] [2] [3] [4]

Fixes #1924

@gvkries gvkries changed the title Simplify using StringValues in Luquid templates Simplify using StringValues in Liquid templates Sep 23, 2025
}

[Obsolete("WriteTo is obsolete, prefer the WriteToAsync method.")]
public override void WriteTo(TextWriter writer, TextEncoder encoder, CultureInfo cultureInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not you call the async version instead of duplicating the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the sync APIs (which are designed to be used in a synchronous way) are safer than doing sync-over-async.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, we planned in Fluid to deprecate this API, so it doesn't make sense to use the Sync version, and later we will be forced to use the Async version

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method here is necessary for backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be removed in the next major release, 3.0.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have a look at the recently added Fluid Values here. AFAIK, we use the async version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Piedone already pointed out, I’d prefer not to rely on sync-over-async in this case. Unlike the other FluidValues you mentioned, this one makes multiple calls to the writer, which introduces additional complexity. Therefore, as long as the method exists, I believe it should be implemented correctly, even if it's marked as obsolete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Liquid Request.Query.SomeValue returns an array
3 participants