【问题标题】:Typo3 using constants in "Constant" fieldTypo3 在“常量”字段中使用常量
【发布时间】:2017-01-12 15:40:22
【问题描述】:

我想形成文件路径。 在“常量”字段中:

const.siteName = site
templates = fileadmin/templates/{$const.siteName}/

当我查看打字稿对象浏览器时:

[siteName] = site    
[templates] = fileadmin/templates/{$const.siteName}/

有没有可能做到这一点:

[templates] = fileadmin/templates/site/

使用const.siteName?

如果是,怎么做?

================================================ ============================

编辑:

接下来我要做的是:

在我的扩展配置中

const.siteName = foo
const.templates = fileadmin/templates/($const.siteName)/
const.path.extensions = ($const.templates)/ext/

我在打字稿模板中包含我的扩展名。在我的扩展设置中,我包括这样的插件设置:

<INCLUDE_TYPOSCRIPT: source="FILE:EXT:foo/Configuration/TypoScript/Plugin/formhandler.ts">

在 Configuration/TypoScript/Plugin/formhandler.ts:

plugin.Tx_Formhandler {
    /* snip */
    settings.predef.member {
        templateFile.value = {$const.path.extensions}formhandler/member/step-1.html // doesn't work
        //templateFile.value = fileadmin/templates/foo/ext/formhandler/member/step-1.html // works
    }
    /* snip */
}

【问题讨论】:

    标签: typo3 typoscript


    【解决方案1】:

    看看 TYPO3 NG/ML/论坛:

    https://forum.typo3.org/index.php?t=msg&th=212721&goto=740111&#msg_740111 有很多提示如何在打字稿中使用常量:

    您可以在常量定义中重用常量,但深度最多只能达到 10 级。

    您可以在条件中使用常量,但只能在设置部分中使用

    【讨论】:

      【解决方案2】:

      对我来说,这个例子很完美:

      常量:

      const.test = foo
      const.test2 = {$const.test}/bar
      

      设置:

      page = PAGE
      
      page.10 = TEXT
      page.10.value = {$const.test}
      page.10.wrap = <p>|</p>
      
      page.20 = TEXT
      page.20.value = {$const.test2}
      page.20.wrap = <p>|</p>
      

      浏览器中的输出:

      foo
      
      foo/bar
      

      使用 TYPO3 4.5 和 8.3 测试

      【讨论】:

      • 但是 TypoScript Objectbrowser 不解析常量部分中的常量。不过,在前端的使用效果很好!
      • 您的示例有效,但不适用于我。请查看我编辑的问题。
      • @EvilPenguin 不要使用 ( ) 而是使用 { } 作为常量,您在其中一个代码示例中弄错了。
      • 我可以补充一点,由于 多个 TypoScript 解析通道,这(有时)在前端有效,当还有剩余的 INCLUDE 语句时会发生这种情况。它可能不会始终在所有网站上发生!并且 如果 它没有发生,constants-inside-constants 可能永远不会被替换。原因是替换发生在str_replace 内部,并且多次通过将第一遍替换为包含第二个引用的内容;然后第二遍替换该引用。如果可以的话,请依靠它,但要小心使用!
      【解决方案3】:

      短:没有

      long:您只能在设置中使用常量。

      你可以做的是:

      常数

      const.siteName = site
      const.templatePath = fileadmin/templates
      

      设置:

      myTemplate= {$const.templatePath}/{$const.siteName}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-25
        • 1970-01-01
        • 2023-04-04
        • 2015-06-15
        • 2019-10-24
        • 1970-01-01
        • 2023-01-05
        相关资源
        最近更新 更多