是否可以在 TypoScript 中比较变量?
是否可以在 TypoScript 中比较变量?如果可能的话——那么如何实现呢?
Is it possible to compare variables in TypoScript? If it is possible - then how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在同样的问题上遇到了困难,所以这就是我发现的。我试图包含一个插件,但前提是已经设置了某个 TypoScript 配置变量,这是使用 TypoScript 条件不可能实现的,因为它们无法访问 TypoScript 变量!
所以真正要走的路是不祥的
if
-函数。该文档说明如下:他们没有提到的是,如果
if
函数返回false
,则相关元素不会显示/执行或其他什么TypoScript 实际上是这样做的,例如:这个 TEXT 元素永远不会被显示,因为条件的计算结果不为 true。但是,将显示以下内容:
if.value
始终保存您要比较的值,然后您可以使用一堆属性来将另一个值与其进行比较。文档中唯一好的示例是这个:
但请注意...这些属性不适用于任何元素类型(例如
USER_INT
,没有它们)。我为解决该问题所做的是将
USER_INT
包装在COA
中,如下所示: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:What they do not mention is, that, if the
if
-function returnsfalse
, the Element in question is just not displayed/executed or whatever TypoScript actually does, for example:This TEXT-element would never be displayed, because the condition does not evaluate to true. The following however, would be displayed:
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:
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 aCOA
as follows:您可以使用 equals 关键字来比较变量。如果您的打字稿是,
那么您可以分配一个
和一个条件
,很抱歉,这是我的记忆,但您可以在打字稿手册中阅读它。我想说这是一个使用相邻树模型的递归数据结构。这是一个链接: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
then you can assign a
and a condition
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
正常的 TypoScript "globalString" 条件是可能的和一个常数:
It's possible with a normal TypoScript "globalString" condition and a constant: