-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Simplify using StringValues
in Liquid templates
#18399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
StringValues
in Luquid templatesStringValues
in Liquid templates
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TemplateOptionsConfigurations.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TemplateOptionsConfigurations.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/StringValuesValue.cs
Show resolved
Hide resolved
Co-authored-by: Zoltán Lehóczky <[email protected]>
Co-authored-by: Zoltán Lehóczky <[email protected]>
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/StringValuesValue.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/StringValuesValue.cs
Show resolved
Hide resolved
} | ||
|
||
[Obsolete("WriteTo is obsolete, prefer the WriteToAsync method.")] | ||
public override void WriteTo(TextWriter writer, TextEncoder encoder, CultureInfo cultureInfo) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 newStringValuesValue
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:
StringValuesValue
class implementingFluidValue
, enabling proper handling ofStringValues
(multi-valued strings) in Liquid templates, including comparison, indexing, iteration, and property access likesize
,first
, andlast
.TemplateOptionsConfigurations.cs
to wrapStringValues
inStringValuesValue
and to register member access strategies forQueryCollection
andHeaderDictionaryWrapper
usingStringValues
, ensuring these HTTP-related values are exposed correctly to Liquid templates. [1] [2] [3]Testing and validation:
LiquidTests.cs
to verifyStringValuesValue
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