Skip to content

[FEATURE] A new <f:contains> ViewHelper should be added to Fluid (#1125) #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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

staatzstreich
Copy link
Contributor

A new <f:contains> ViewHelper should be added to Fluid, which checks if a provided value either exists in the provided array or in the provided string. If both the array and the string are provided, an exception should be thrown. This ViewHelper extends the AbstractConditionViewHelper.

Arguments:

mixed $value (needs to be scalar if f:contains is used with the string argument)
array $array
string $string
See also the php in_array() and the php str_contains() functions.

Examples:

<f:contains value="foo" array="{myArray}">

</f:contains>
<f:contains value="foo" string="{myString}">

</f:contains>

<f:variable name="result" value="{f:contains(value: 'foo', array: myArray)}" />

@mbrodala
Copy link
Contributor

mbrodala commented Aug 14, 2025

I wonder if we should consider extending conditions instead, e.g. using Symfony EL:

{myString contains "foo"}

Then we'd not need to add a viewhelper for each and every bit of functionality.

@s2b
Copy link
Contributor

s2b commented Aug 17, 2025

@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)} && ...">

@s2b
Copy link
Contributor

s2b commented Aug 19, 2025

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:

  • Allow both array and string as one argument and differentiate in the VH based on the type
  • Split into two: f:contains for strings and f:in for arrays

What do you think?

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.

3 participants