Get TypoScript configuration everywhere


/ Published in: PHP
Save to your folder(s)

I hate to configure everything twice or more often. So I use typoscript to configure everything at one place. To get this configuration in my php-scripts (perhaps a hook) I use this little Code:


First you need to include the typoscript parser. The you have to read your typoscript file. Then you can parse the file content.
$tsParser->setup contains the parsed typoscript.


Copy this code and paste it in your HTML
  1. /**
  2.  * Parses the typoscript of an sys_template.
  3.  * NOTICE: Constants won't be solved.
  4.  *
  5.  * @param integer $typoScriptUid The uid of the sys_template.
  6.  * @return array The typoscript confirugation, without the ".".
  7.  *
  8.  * @author Daniel Siepmann < [email protected] >
  9.  */
  10. static function getTypoScriptFromDb($typoScriptUid) {
  11. require_once t3lib_div::getFileAbsFileName("t3lib/class.t3lib_tsparser.php",
  12. false,
  13. false);
  14. require_once t3lib_div::getFileAbsFileName("typo3/sysext/extbase/Classes/Utility/TypoScript.php",
  15. false,
  16. false);
  17. $rawTypoScript = $GLOBALS["TYPO3_DB"]->exec_SELECTgetRows(
  18. " config ",
  19. " sys_template ",
  20. " uid = " . $typoScriptUid
  21. );
  22. $tsParser = new t3lib_TSparser();
  23. $tsParser->parse(t3lib_TSparser::checkIncludeLines($rawTypoScript[0]["config"]));
  24. return Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($tsParser->setup);
  25. }
  26.  
  27. /**
  28.  * Parses a typoscript file.
  29.  * NOTICE: Constants and includes won't be solved.
  30.  *
  31.  * @param string $file The file name of the file you want to parse. With complete parse like "fileadmin/typoscript/setup.ts".
  32.  * @return array The typoscript confirugation, without the ".".
  33.  *
  34.  * @author Daniel Siepmann < [email protected] >
  35.  */
  36. static function getTypoScriptFromFile($file) {
  37. require_once t3lib_div::getFileAbsFileName("t3lib/class.t3lib_tsparser.php",
  38. false,
  39. false);
  40. require_once t3lib_div::getFileAbsFileName("typo3/sysext/extbase/Classes/Utility/TypoScript.php",
  41. false,
  42. false);
  43. $tsFileName = t3lib_div::getFileAbsFileName($file,
  44. false,
  45. false);
  46. $tsParser = new t3lib_TSparser();
  47. $tsFile = fopen($tsFileName,
  48. "r");
  49. $tsParser->parse(fread($tsFile,
  50. filesize($tsFileName)));
  51. return Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($tsParser->setup);
  52. }

URL: http://wiki.typo3.org/User:Layne_obserdia/Backend

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.