-
Notifications
You must be signed in to change notification settings - Fork 106
[FEATURE] <f:contains> ViewHelper #1193
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
Conversation
|
I wonder if we should consider extending conditions instead, e.g. using Symfony EL: Then we'd not need to add a viewhelper for each and every bit of functionality. |
|
@mbrodala I agree that we should improve conditions overall. However, in the short term it's probably wise to add ViewHelpers for the most common use cases nonetheless. Also, the following syntax is already possible: <f:if condition="{f:contains(value: 'foo', array: myArray)} && ..."> |
|
The more I think about it, the more I struggle with the VH API. I'm open to other suggestions, but these come to mind:
What do you think? |
IMHO there should be two dedicated view helpers as you suggested to handle the different types. Additionally, for an f:in view helper (better f:inArray as the purpose is clearer) we should think about the possibility for checking the type (like in_array in PHP with the "strict" argument): With "strict" be false by default (like in PHP). Strictness might be difficult when setting a value directly in Fluid: Here the value is a string while the array values might be ints. But that would work: if {someValue} is passed to Fluid and is really an int. |
|
Thank you for your input here! We discussed this again and we came to the conclusion that we will have one So the subject will support both string and array (+ array-like objects). I get the arguments for type strictness, but in my opinion, convenience and consistent naming is more important in a template engine. I'll adjust the implementation accordingly in the next few days. |
3d6a335 to
9a42ac3
Compare
9a42ac3 to
0e3d357
Compare
|
I've adjusted the ViewHelper and documentation. WDYT? |
This patch adds a new `<f:contains>` ViewHelper to Fluid, which allows to check if a provided string or array contains a specified value. Depending on the input, this mimicks PHP's `in_array()` or `str_contains()`. The initial version of this patch is intended to be backported to Fluid 4. In a follow-up, the code and argument types can be improved for Fluid 5. Resolves: #1125
This patch adds a new `<f:contains>` ViewHelper to Fluid, which allows to check if a provided string or array contains a specified value. Depending on the input, this mimicks PHP's `in_array()` or `str_contains()`. The initial version of this patch is intended to be backported to Fluid 4. In a follow-up, the code and argument types can be improved for Fluid 5. Resolves: #1125 Co-authored-by: Michael Staatz <michael@staatzstreich.de>
This patch adds a new
<f:contains>ViewHelper to Fluid, which allowsto check if a provided string or array contains a specified value.
Depending on the input, this mimicks PHP's
in_array()orstr_contains().The initial version of this patch is intended to be backported to Fluid 4.
In a follow-up, the code and argument types can be improved for Fluid 5.
Resolves: #1125