我正在寻找一个解决方案,如何在additionalAttributes中包含一个查询?
静态:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{rel:'nofollow'}">
Link
</f:link.typolink>条件:
<f:variable name="nofollow"><f:if condition="{field.referenceLinkNofollow}"><f:then>{rel:'nofollow'}</f:then><f:else>{rel:'dofollow'}</f:else></f:if></f:variable>下一次测试:
<f:section name="nofollow">
<f:spaceless><f:if condition="{field.referenceLinkNofollow}"><f:then>{rel:'nofollow'}</f:then><f:else>{rel:'dofollow'}</f:else></f:if></f:spaceless>
</f:section>不像这样工作:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{nofollow}">
Link
</f:link.typolink>错误:
参数"additionalAttributes“已用”additionalAttributes“类型注册,但在视图助手additionalAttributes中为"string”类型。
发布于 2022-01-23 07:49:03
一种选择可以是:
<f:variable name="nofollow" value="{f:if(condition: '{data.no_follow}', then: 'nofollow', else: '')}" />
<f:link.typolink parameter="https://example.com" title="Title" additionalAttributes="{rel: '{nofollow}'}">
Link
<f:link.typolink>让我们假设变量{data.no_follow}表示后端用户可以更改页面属性的设置(“跟随此页面”)。
第一行根据页面属性设置将流体模板中的变量nofollow设置为值'nofollow'或'' (空)。我使用了If-ViewHelper的内联表示法来实现这一点。然后在LinkTypolink-ViewHelper中使用变量{nofollow}作为rel=属性在additionalAttributes下的值。
当空值被删除时,只有当rel=属性有值时,才会显示它。
发布于 2022-01-23 14:55:00
如果{field.referenceLink}和{field.referenceLinkNofollow}包含所需数据,则此操作也应有效。
<f:link.typolink parameter="{field.referenceLink}"
additionalAttributes="{f:if(condition: '{field.referenceLinkNofollow}', then: '{rel:'nofollow'}')}"
>Linktext</f:link.typolink>发布于 2022-01-23 21:30:08
谢谢,很管用!
<f:variable name="nofollow" value="{f:if(condition: '{field.referenceLinkNofollow}', then: 'nofollow', else: '')}" />流体:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel}" additionalAttributes="{rel: '{nofollow}'}">https://stackoverflow.com/questions/70815416
复制相似问题