[英]TYPO3 - f:link.typolink with additionalAttributes and a condition?
I am looking for a solution, how to include a query in additionalAttributes?我正在寻找解决方案,如何在附加属性中包含查询?
Static: Static:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{rel:'nofollow'}">
Link
</f:link.typolink>
condition:健康)状况:
<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>
next Test:下一个测试:
<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>
Dont Work like this:不要这样工作:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{nofollow}">
Link
</f:link.typolink>
Error:错误:
The argument "additionalAttributes" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\Link\TypolinkViewHelper".参数“additionalAttributes”注册为“array”类型,但在视图助手“TYPO3\CMS\Fluid\ViewHelpers\Link\TypolinkViewHelper”中属于“string”类型。
One option could be:一种选择可能是:
<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>
Let's assume that the variable {data.no_follow}
represents the setting that backend users can change in the page properties ("Follow this page").假设变量
{data.no_follow}
表示后端用户可以在页面属性中更改的设置(“关注此页面”)。
The first line sets the variable nofollow
in the Fluid template to either the value 'nofollow'
or to ''
( empty ), depending on the page property setting.第一行将 Fluid 模板中的变量
nofollow
设置为值'nofollow'
或''
( empty ),具体取决于页面属性设置。 I have used the inline notation of the If -ViewHelper to achieve this.我使用If -ViewHelper 的内联符号来实现这一点。 The variable
{nofollow}
is then used in the LinkTypolink -ViewHelper as the value for the rel=
attribute under additionalAttributes
.然后在LinkTypolink -ViewHelper 中使用变量
{nofollow}
作为additionalAttributes
下rel=
属性的值。
As empty values are dropped, the rel=
attribute is only shown if it has value.由于删除了空值,因此
rel=
属性仅在它具有值时才显示。
This should also work if {field.referenceLink} and {field.referenceLinkNofollow} contains da needed data.如果 {field.referenceLink} 和 {field.referenceLinkNofollow} 包含所需的数据,这也应该有效。
<f:link.typolink parameter="{field.referenceLink}"
additionalAttributes="{f:if(condition: '{field.referenceLinkNofollow}', then: '{rel:'nofollow'}')}"
>Linktext</f:link.typolink>
thanks, it works!谢谢,它有效!
<f:variable name="nofollow" value="{f:if(condition: '{field.referenceLinkNofollow}', then: 'nofollow', else: '')}" />
fluid:体液:
<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel}" additionalAttributes="{rel: '{nofollow}'}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.