是否可以在 TypoScript 中比较变量?

发布于 2024-11-30 15:06:56 字数 46 浏览 3 评论 0原文

是否可以在 TypoScript 中比较变量?如果可能的话——那么如何实现呢?

Is it possible to compare variables in TypoScript? If it is possible - then how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

公布 2024-12-07 15:06:56

我在同样的问题上遇到了困难,所以这就是我发现的。我试图包含一个插件,但前提是已经设置了某个 TypoScript 配置变量,这是使用 TypoScript 条件不可能实现的,因为它们无法访问 TypoScript 变量!

所以真正要走的路是不祥的 if-函数。该文档说明如下:

如果满足所有当前条件(它们是“与”运算),则该函数返回 true。如果单个条件为 false,则返回值为 false。

他们没有提到的是,如果if函数返回false,则相关元素不会显示/执行或其他什么TypoScript 实际上是这样做的,例如:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.equals = 24

这个 TEXT 元素永远不会被显示,因为条件的计算结果不为 true。但是,将显示以下内容:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.isGreaterThan = 24

if.value 始终保存您要比较的值,然后您可以使用一堆属性来将另一个值与其进行比较。

文档中唯一好的示例是这个:

这是一个 GIFBUILDER 对象,如果“newUntil”字段的日期小于当前日期,它将在菜单项上写入“NEW”!

...
30 = TEXT
30.text = NEW!
30.offset = 10,10
30.if {
    value.data = date: U
    isLessThan.field = newUntil
    negate = 1
}
...

但请注意...这些属性不适用于任何元素类型(例如USER_INT,没有它们)

我为解决该问题所做的是将 USER_INT 包装在 COA 中,如下所示:

config.enableMyStuff = 1
page.20 = COA
page.20 {
    10 =< plugin.tx_myextension_pi1
    if.value < config.enableMyStuff
    if.equals = 1
}

I struggled with the very same issue, so here is what I found out. I was trying to include a plugin, but only if a certain TypoScript configuration variable was already set, which isn't possible using TypoScript conditions, because these don't have access to TypoScript variables!

So the way to go really is the ominous if-function. The documentation says the following:

This function returns true if ALL of the present conditions are met (they are AND'ed). If a single condition is false, the value returned is false.

What they do not mention is, that, if the if-function returns false, the Element in question is just not displayed/executed or whatever TypoScript actually does, for example:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.equals = 24

This TEXT-element would never be displayed, because the condition does not evaluate to true. The following however, would be displayed:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.isGreaterThan = 24

if.value always holds the value you are comparing to, and then there are a bunch of property you may use to compare another value to it.

The only good example in the documentation is this one:

This is a GIFBUILDER object that will write "NEW" on a menu-item if the field "newUntil" has a date less than the current date!

...
30 = TEXT
30.text = NEW!
30.offset = 10,10
30.if {
    value.data = date: U
    isLessThan.field = newUntil
    negate = 1
}
...

But beware... these properties are not available on any element type (USER_INT for example, does not have them).

What I did to workaround that problem was to wrap the USER_INT in a COA as follows:

config.enableMyStuff = 1
page.20 = COA
page.20 {
    10 =< plugin.tx_myextension_pi1
    if.value < config.enableMyStuff
    if.equals = 1
}
眼前雾蒙蒙 2024-12-07 15:06:56

您可以使用 equals 关键字来比较变量。如果您的打字稿是,

10.value = 10

那么您可以分配一个

10.equals = 10

和一个条件

10.iftrue = 20

,很抱歉,这是我的记忆,但您可以在打字稿手册中阅读它。我想说这是一个使用相邻树模型的递归数据结构。这是一个链接:http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621713

You can compare variables by using the equals-keyword. If you typoscript is

10.value = 10

then you can assign a

10.equals = 10

and a condition

10.iftrue = 20

I'm sorry it's from my memory but you can read it in the typoscript manual. I want to say it's a recursive data structure using an adjacent tree model. Here is a link: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621713

我只土不豪 2024-12-07 15:06:56

正常的 TypoScript "globalString" 条件是可能的和一个常数:

[globalString = LIT:foobar = {$some.typoscript.constant}]
    ...
[global]

It's possible with a normal TypoScript "globalString" condition and a constant:

[globalString = LIT:foobar = {$some.typoscript.constant}]
    ...
[global]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文