Geht es euch oft nicht genauso, das ihr eine Extension verwendet, die zwar vermutlich HTML Templates mitbringt, das man aber keine Möglichkeit hat, weitere Marker dort einzubauen?
Eventuell gibt es ja dann doch noch einen Hook (so wie bei tt_news), mit dem man den MarkerArray erweitern kann, aber es kann einfacher – eben ohne Zusatzextension – funktionieren!
Zuerst kam mir die Idee bei der Erstellung von powermail: Durch Einfügen eines bestimmten Markes in irgendeinem der HTML Templates, sollte Typoscript ausgeführt oder einfach nur ein Wert aus der locallang.xml genommen werden – eben ###TYPOSCRIPT_MYMARKER### oder ###LOCALLANG_MYMARKER###
Umsetzung:
Im Prinzip ist die Umsetzung bei der Erstellung einer Extension auch nicht unbedingt schwer. Nachdem der Template Code mit Markern befüllt wurde und vor der Rückgabe von $content kann eine Methode zum Einsatz kommen, die den übergebenen HTML Code nach besagten Markern durchforstet und befüllt:
$this->dynTS = t3lib_div::makeInstance('tx_ext_dynamicmarkers'); // Get dynamic Typoscript methods ... $content = $this->cObj->substituteMarkerArrayCached($template, $markerArray); // substitute Marker in Template $content = $this->dynTS->main($content, $this); // Fill dynamic locallang or typoscript markers return $content; |
Die Klasse die über eine kleine regEx nach solchen Markern sucht und diese dann mit TS oder mit Werten aus der locallang befüllt, kann dabei so aussehen (In einem Array kann man definieren, wie diese Marker auszusehen haben – z.B. ###FESTERWERT_MYMARKER###):
require_once(PATH_tslib.'class.tslib_pibase.php'); class tx_ext_dynamicmarkers extends tslib_pibase { public $extKey = 'extKey'; // Extension key public $prefixId = 'tx_ext_pi1'; // Same as class name public $scriptRelPath = 'pi1/class.tx_ext_pi1.php'; // Path to any script in pi1 for locallang protected $locallangmarker_prefix = array('EXT_LL_', 'ext_ll_'); // prefix for automatic locallangmarker protected $typoscriptmarker_prefix = array('EXT_TS_', 'ext_ts'); // prefix for automatic typoscriptmarker public function main($content, $pObj) { // config $this->conf = $pObj->conf; // conf $this->cObj = $pObj->cObj; // cObj $this->piVars = $pObj->piVars; // piVars $this->content = $content; $this->pi_loadLL(); // let's go // 1. replace locallang markers $this->content = preg_replace_callback ( // Automaticly fill locallangmarkers with fitting value of locallang.xml '#\#\#\#'.$this->locallangmarker_prefix[0].'(.*)\#\#\##Uis', // regulare expression array($this, 'dynamicLocalLangMarker'), // open function $this->content // current content ); // 2. replace typoscript markers $this->content = preg_replace_callback ( // Automaticly fill locallangmarkers with fitting value of locallang.xml '#\#\#\#'.$this->typoscriptmarker_prefix[0].'(.*)\#\#\##Uis', // regulare expression array($this, 'dynamicTyposcriptMarker'), // open function $this->content // current content ); if (!empty($this->content)) return $this->content; } protected function dynamicLocalLangMarker($array) { if (!empty($array[1])) $string = $this->pi_getLL(strtolower($this->locallangmarker_prefix[1].$array[1]), '<i>'.strtolower($array[1]).'</i>'); // search for a fitting entry if (!empty($string)) return $string; } protected function dynamicTyposcriptMarker($array) { if ($this->conf[$this->typoscriptmarker_prefix[1].'.'][strtolower($array[1])]) { // If there is a fitting entry in typoscript $string = $this->cObj->cObjGetSingle($this->conf[$this->typoscriptmarker_prefix[1].'.'][strtolower($array[1])], $this->conf[$this->typoscriptmarker_prefix[1].'.'][strtolower($array[1]).'.']); // fill string with typoscript value } if (!empty($string)) return $string; } } |
Das Ganze nochmal etwas größer um den Code besser zu kopieren (Beispiel aus Extension minicrm).
Der Typoscript Teil:
# Fill Marker ###EXT_TS_MYFIELD### - dynamictyposcriptmarker plugin.tx_ext_pi1.ext_ts.myfield = TEXT plugin.tx_ext_pi1.ext_ts.myfield.value = blabla plugin.tx_ext_pi1.ext_ts.myfield.wrap = <b>|</b> # Fill Marker ###EXT_LL_MYFIELD### - dynamiclocallangmarker plugin.tx_ext_pi1._LOCAL_LANG.de.ext_ll_myfield = Schreib das ins Template plugin.tx_ext_pi1._LOCAL_LANG.en.ext_ll_myfield = Write this in my template |
Fazit:
Was bringt das Ganze?
Mehr Flexibilität für die Leute die eure Extensions einsetzen. Sie können jederzeit und überall ihr eigenes Typoscript oder eigene Werte aus der locallang in eurem HTML Template unterbringen.
Ein wichtiger Punkt ist natürlich die Performance. Bislang konnte ich keine negativen Auswirkungen feststellen, lasse mich aber eines Besseren belehren.
Links:
– Wie das ganze bei powermail Funktioniert ist im Manual beschrieben
– Typoscript stdWrap mit cObjGetSingle in eigener Extension
Cheers, Alex
PS: Hilfreich? Nonsense? Diskussion!