【问题标题】:How do I solve a strange problem with VHS ViewHelper v:replace?如何解决 VHS ViewHelper v:replace 的一个奇怪问题?
【发布时间】:2023-04-01 10:37:02
【问题描述】:

我有一个数组 ('db-titles'),它的项目是以 'TextA*TextB' 形式组成的字符串。 我想从这些数组项中创建以下 HTML 结构:<span>TextA</span><span>TextB</span>

为此,我使用以下流畅的脚本:

{namespace v=FluidTYPO3\Vhs\ViewHelpers}

<f:if condition="{db-titles -> f:count()} > 1">

  <f:then>

     <!-- This works as expected, the html code will be rendered correctly -->
     <v:iterator.for from="0" to="{db-titles -> f:count()}" iteration="i">
        <span><v:format.replace content="{db-titles.{i.index}}" substring="*" replacement="</span><span>"/></span>
     </v:iterator.for>

  </f:then>

  <f:else> 
       <!-- This strangely does not work, although I - instead of running through all values of the array - just want to output the first value of it.... -->      
       <span><v:format.replace content="{v:iterator.first(haystack: db-titles)}" substring="*" replacement="</span><span>"/></span>
  </f:else>

</f:if>

正如我在源代码中评论的那样,在“”下一切正常,但在“”下,我只想使用数组的第一个值,替换部分('*' to &lt;/span&gt;&lt;span&gt;)奇怪地呈现为文本而不是 HTML:&lt;span&gt;TextA&amp;lt;/span&amp;gt;&amp;lt;span&amp;gt;TextB&lt;/span&gt;

这怎么可能?

让我提一下,我使用“PHPStorm”应用程序进行编程 - 程序是否有可能将源代码呈现错误?

提前感谢您的帮助!

【问题讨论】:

    标签: typo3 fluid view-helpers


    【解决方案1】:

    在没有找到奇怪行为的解释的情况下,我找到了一个解决方案:用&lt;f:format.raw&gt; ... &lt;/&gt; 包装&lt;v:format.replace ... /&gt; 可以防止标签转换为字符串。

    <f:if condition="{db-titles -> f:count()} > 1">
    
      <f:then>
         <v:iterator.for from="0" to="{db-titles -> f:count()}" iteration="i">
            <span><f:format.raw><v:format.replace content="{db-titles.{i.index}}" substring="*" replacement="</span><span>"/></f:format.raw></span>
         </v:iterator.for>
      </f:then>
    
      <f:else>       
         <span><f:format.raw><v:format.replace content="{v:iterator.first(haystack: db-titles)}" substring="*" replacement="</span><span>"/></(f:format.raw></span>
      </f:else>
    
    </f:if>
    

    【讨论】:

      猜你喜欢
      • 2011-11-17
      • 2021-07-24
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      相关资源
      最近更新 更多