How to access the ext_conf_template.txt (extension configuration) in typoscript?

旧街凉风 提交于 2019-12-24 06:35:20

问题


There are a few settings in the ext_conf_template.txt in my extension.

I want to check the value of one of these settings, but in typoscript, not in PHP.

In PHP it works like this:

unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['myExt'])

How should I do this in typoscript?


回答1:


I did something similar in my code snippet extension (see complete code on Github), where I just added a custom TypoScript condition:

[DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching\AllLanguagesCondition]
  // some conditional TS
[global]

The condition implementation is quite simple:

namespace DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching;
use DanielGoerz\FsCodeSnippet\Utility\FsCodeSnippetConfigurationUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;

class AllLanguagesCondition extends AbstractCondition
{
    /**
     * Check whether allLanguages is enabled
     * @param array $conditionParameters
     * @return bool
     */
    public function matchCondition(array $conditionParameters)
    {
        return FsCodeSnippetConfigurationUtility::isAllLanguagesEnabled();
    }
}

And the check for the actual TYPO3_CONF_VARS value is done in FsCodeSnippetConfigurationUtility:

namespace DanielGoerz\FsCodeSnippet\Utility;    
class FsCodeSnippetConfigurationUtility
{
    /**
     * @return array
     */
    private static function getExtensionConfiguration()
    {
        return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fs_code_snippet']);
    }
    /**
     * @return bool
     */
    public static function isAllLanguagesEnabled()
    {
        $conf = self::getExtensionConfiguration();
        return !empty($conf['enableAllLanguages']);
    }

}

Maybe that fits your needs.




回答2:


Handle the configuration via Extension Manager and call ExtensionManagementUtility::addTypoScriptConstants() in your ext_localconf.php to set a TypoScript constant at runtime.

This way the value can be set at one location and is available both in lowlevel PHP and TypoScript setup.



来源:https://stackoverflow.com/questions/43537748/how-to-access-the-ext-conf-template-txt-extension-configuration-in-typoscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!