问题描述
我有一个数组(“ 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>
正如我在源代码中评论的那样,一切在“ </span><span>
)奇怪地呈现为文本而不是HTML:<span>TextA</span><span>TextB</span>
怎么可能?
让我提到我使用应用程序“ PHPStorm”进行编程-程序是否可能将源代码渲染为错误?
在此先感谢您的帮助!
解决方法
在没有找到奇怪行为的解释的情况下,我找到了一种解决方案:用<v:format.replace ... />
包装<f:format.raw> ... </>
可以防止将标签转换为字符串。
<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>