Wert aus Flexform per TS lesen

Armin Bartsch, Dienstag, 10. März 2009

Zur Zeit ist es nicht möglich per TS ein Flexform-Werte direkt auszulesen. Eine kleine USER-Funktion macht dies aber möglich

Damit die umfangreiche Konfigurationsmöglichkeit von TYPO3 weiter genutzt werden kann, wird zum auslesen des Datensatz aus das CObject RECORDS und für den Flexformwertes auf USER zurückgegriffen.

TypoScript

# Hier müssen Sie evtl. den Pfad zur flexform_order.php anpassen includeLibs.flexform_order_pi = fileadmin/flexform_order.php temp.flexform = RECORDS temp.flexform { tables = tt_content source = 214 conf.tt_content = COA conf.tt_content { 10 = USER 10 { userFunc = user_flexform_order_pi->field # Name des Feldes mit Flexform (XML) field = tx_templavoila_flex # Name des FlexForm-Data flex_data = field_a69d3f # Sheet Pointer, standard ist sDEF sheet_pointer = sDEF # Sprache, standard ist lDEF lang = lDEF # Value, standard = vDEF value_def = vDEF } } } lib.footer.2221 < temp.flexform
  1. # Hier müssen Sie evtl. den Pfad zur flexform_order.php anpassen
  2. includeLibs.flexform_order_pi =  fileadmin/flexform_order.php
  3.  
  4. temp.flexform = RECORDS
  5. temp.flexform {
  6.  
  7.   tables = tt_content
  8.   source = 214
  9.  
  10.   conf.tt_content = COA
  11.   conf.tt_content {
  12.  
  13.     10 = USER
  14.     10 {
  15.  
  16.       userFunc = user_flexform_order_pi->field
  17.       # Name des Feldes mit Flexform (XML)
  18.       field = tx_templavoila_flex
  19.       # Name des FlexForm-Data
  20.       flex_data = field_a69d3f
  21.       # Sheet Pointer, standard ist sDEF
  22.       sheet_pointer = sDEF
  23.       # Sprache, standard ist lDEF
  24.       lang = lDEF
  25.       # Value, standard = vDEF
  26.       value_def = vDEF
  27.    
  28.     }
  29.    
  30.   }
  31.  
  32. }
  33.  
  34. lib.footer.2221 < temp.flexform

USER - Funktion

Jetzt erstellen die eine PHP-Datei mit folgenden Inhalt:

<?php /*************************************************************** * Copyright notice * * (c) 2006 Armin Bartsch http://typo3.intervation.de * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ require_once(PATH_tslib.'class.tslib_pibase.php'); class user_flexform_order_pi extends tslib_pibase { function field($content, $conf) { $this->pi_loadLL(); $this->pi_setPiVarDefaults(); $this->pi_initPIflexForm(); $flex_array = t3lib_div::xml2array($this->cObj->data[''.$conf['field'].'']); $tv_field = $this->pi_getFFvalue($flex_array, $conf['flex_data'], $conf['sheet_pointer'], $conf['lang'], $conf['value_def']); return $tv_field; } } ?>
  1. <?php
  2. /***************************************************************
  3. *  Copyright notice
  4. *
  5. *  (c) 2006 Armin Bartsch http://typo3.intervation.de
  6. *  All rights reserved
  7. *
  8. *  This script is part of the Typo3 project. The Typo3 project is
  9. *  free software; you can redistribute it and/or modify
  10. *  it under the terms of the GNU General Public License as published by
  11. *  the Free Software Foundation; either version 2 of the License, or
  12. *  (at your option) any later version.
  13. *
  14. *  The GNU General Public License can be found at
  15. *  http://www.gnu.org/copyleft/gpl.html.
  16. *
  17. *  This script is distributed in the hope that it will be useful,
  18. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. *  GNU General Public License for more details.
  21. *
  22. *  This copyright notice MUST APPEAR in all copies of the script!
  23. ***************************************************************/
  24.  
  25. require_once(PATH_tslib.'class.tslib_pibase.php');
  26.  
  27. class user_flexform_order_pi extends tslib_pibase {
  28.  
  29.   function field($content, $conf) {
  30.  
  31.     $this->pi_loadLL();
  32.     $this->pi_setPiVarDefaults();
  33.     $this->pi_initPIflexForm();
  34.        
  35.     $flex_array = t3lib_div::xml2array($this->cObj->data[''.$conf['field'].'']);
  36.     $tv_field = $this->pi_getFFvalue($flex_array, $conf['flex_data'], $conf['sheet_pointer'], $conf['lang'], $conf['value_def']);
  37.  
  38.     return $tv_field;
  39.  
  40.   }
  41.  
  42. }
  43. ?>

Sponsored by:

ideenwerft webhosting
ideenwerft caretaker