Search code examples
typo3typoscript

How can I display the version of my sitepackage in the frontend?


I want to display the version of my sitepackage (from my declaration file ext_emconf.php ) in the frontend.

How do I query this information? I was thinking of using a DataProcessor in my FLUIDTEMPLATE, but I’m not sure whether I need to write my own or if there’s already one I can use for that.

Thank you!


Solution

  • Depending on your exact needs you could make use of ExtensionManagementUtility::getExtensionVersion() to inject a global TypoScript constant via ExtensionManagementUtility::addTypoScriptConstants():

    // ext_localconf.php
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants(sprintf(
        'site.version = %s',
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('sitepackage')
    ));
    

    Afterwards you can use this constant anywhere in TypoScript setup including variables of Fluid templates:

    // TypoScript setup
    10 = FLUIDTEMPLATE
    10 {
      // ...
      variables {
        siteVersion = {$site.version}
      }
    }
    

    Now use this variable anywhere you like in your template:

    <!-- Fluid template -->
    <p>Site {siteVersion}</p>