3

是否可以在 TypoScript 条件下使用 TypoScript 中定义的变量?

例如,如果我定义这样的变量:

my_var = 10

我可以在打字稿中创建一个条件来检查是否my_var等于 10?我想象这样的事情:

my_var = 10
[my_var = 10]
# do something
[else]
# do something else
[end]

我需要这个的原因是缺少嵌套条件。如果我要求的是可能的,我可以做这样的事情来克服这个限制:

[globalVar=TSFE:id=1]
# render special layout for page 1
[else]
normal_layout = 1
[end]
[normal_layout = 1] && [globalVar=TSFE:page|layout=1]
# render normal layout 1
[end]
[normal_layout = 1] && [globalVar=TSFE:page|layout=2]
# render normal layout 2
[end]

另一个用例是检查变量是否存在,例如是否page已经定义。例子:

[globalVar=TSFE:id=1]
    page = PAGE
    page.10 = TEXT
    page.10.value = hello page 1!
[end]
[!page]
    page = PAGE
    page.10 = TEXT
    page.10.value = hello world!
[end]

我很惊讶文档还没有回答这个问题:S

编辑

我已经尝试过 Andreas Ottos 解决方案,但它似乎仍然不起作用。这是我的示例代码:

lib.content = TEXT
lib.content.value = this text should not get displayed

[globalVar=TSFE:id=1] 
lib.content = TEXT
lib.content.value = this is page 1
[else]
normal_layout = 1
[end]

[globalVar = LIT:1 = {$normal_layout}]
lib.content = TEXT
lib.content.value = this is any other page
[end]
page = PAGE
page.10 < lib.content

理论上,这应该为第 1 页呈现“这是第 1 页”,而为任何其他页面呈现“这是任何其他页面”。但是,虽然第 1 页正确呈现,但其他页面并非如此。它们被渲染为“不应显示此文本”。

有任何想法吗?我使用的是 7.6 版。这可能是问题吗?

4

1 回答 1

2

编辑:对于第一个用例:可以使用 TypoScript“文字”。在此处的文档中查看一个小提示。而且您必须将常量与逻辑分开。

所以在常量中你必须写:

[globalVar=TSFE:id=1]
normal_layout = 0
[else]
normal_layout = 1
[end]

在设置部分你可以使用这个变量:

[globalVar = LIT:0 = {$normal_layout}]
    # render special layout for page 1
[end]

[globalVar = LIT:1 = {$normal_layout}] && [globalVar=TSFE:page|layout=1]
# render normal layout 1
[end]

[globalVar = LIT:1 = {$normal_layout}] && [globalVar=TSFE:page|layout=2]
# render normal layout 2
[end]

您的第二个用例不是很清楚,但我建议使用在特定情况下被覆盖的页面的基本定义。

于 2016-05-18T15:38:29.637 回答