检查字符串是否包含 VHS 2.4 中的子字符串

Check if string contains substring in VHS 2.4

如何检查字符串是否包含特定子字符串? 例如。我有一个名为 {category.files} 的对象数组,并输出每个对象名称。

<f:for each="{category.files}" as="file">
    <p>{file.name}</p>
</f:for>

现在我尝试检查名称是否包含特定子字符串,如果为真则输出它?在我的例子中,我搜索子字符串 fire.

我找到了 VHS 方法 contains 但我不知道如何使用它,因为没有包含真实示例。

我的情况如何?

<f:for each="{category.files}" as="file">
                                  ???            ???                 ??
    <v:if.string.contains then="[mixed]" else="[mixed]" haystack="{file}" needle="fire">
       <!--output it if found -->

       <!-- else, do nothing -->
    </v:if.string.contains>
</f:for>

所以换句话说,我尝试在 haystack 中搜索 fire

heystack = string to compare
needle   = string to find

如果{file.name}可以打针你应该这样做:

  <f:for each="{category.files}" as="file">
    <v:condition.string.contains haystack="{file.name}" needle="fire">
      <f:then>
        Needle found
      </f:then>
      <f:else>
        Needle not found
      </f:else>
    </v:condition.string.contains>
  </f:for>

已编辑:如评论中所述,要求的 ViewHelper v:if.string.contains 在使用的​​版本中已重命名为 v:condition.string.contains