.. ================================================== .. FOR YOUR INFORMATION .. -------------------------------------------------- .. -*- coding: utf-8 -*- with BOM. .. ================================================== .. DEFINE SOME TEXTROLES .. -------------------------------------------------- .. role:: underline .. role:: typoscript(code) .. role:: ts(typoscript) :class: typoscript .. role:: php(code) Getting the value of the Plugin FlexForm field ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In the mininews plugin class we first need to detect if a Template Object record is pointed at and if so make sure it is used. Detecting the Template Object (TO) record """"""""""""""""""""""""""""""""""""""""" In the “mininews/pi1/class.tx\_mininews\_pi1.php” file the class contains these two variables: :: // TemplaVoilà! Plus specific: var $TA=''; // If TemplaVoilà! Plus is used and a TO record is found, this array will be loaded with Template Array. var $TMPLobj=''; // Template Object Later, in the listView function you find this initialization which detects the record. Comments below :: 1: function listView($content,$conf) { 2: 3: // Init FlexForm configuration for plugin: 4: $this->pi_initPIflexForm(); 5: 6: // Looking for TemplaVoilà! Plus TO record and if found, initialize template object: 7: if (t3lib_extMgm::isLoaded('templavoilaplus')) { 8: $field_templateObject = $this->pi_getFFvalue($this->cObj->data['pi_flexform'],'field_templateObject'); 9: if ((int)$field_templateObject) { 10: $this->TMPLobj = t3lib_div::makeInstance(\Ppi\TemplaVoilaPlus\Domain\Model\HtmlMarkup::class); 11: $this->TA = $this->TMPLobj->getTemplateArrayForTO((int)$field_templateObject); 12: if (is_array($this->TA)) { 13: $this->TMPLobj->setHeaderBodyParts($this->TMPLobj->tDat['MappingInfo_head'],$this->TMPLobj->tDat['MappingData_head_cached']); 14: } 15: } 16: } - Line 4 initializes the “pi\_flexform” field in $this->cObj->data. This will convert the field from being a string with the XML data to being an array with the same XML converted to PHP array by t3lib\_div::xml2array() - Line 7 checks if TemplaVoilà! Plus is loaded -which it must be of course! - Line 8 requests the value of “field\_templateObject” in the FlexForm content of “pi\_flexform” - Line 9 sees in that value is an integer - which means it points to a Template Object record “uid” - In line 10 we create an instance of the “\Ppi\TemplaVoilaPlus\Domain\Model\HtmlMarkup::class” class which will be our API for merging our *data* from mininews with the *template* from the Template Object record. - Line 11 loads the Template Array from the TO pointed to by $field\_templateObject. - Line 12 checks if the Template Array was set - this is the case if there was mapping information found in the TO. - Line 13 will set possible header sections if any should be defined in the TO. Now, in the rest of the mininews class we can just check if $this->TA is an array and if so use TemplaVoilà! Plus API for merging data and template. This is shown next. Merging Data with Template markup """"""""""""""""""""""""""""""""" In order to not make this too lengthy I will just cut out some examples. **Repeated list rows** The first example is how to accumulate content for list rows. This is basically done by a loop, traversing over the elements and for each iteration calling an API function in TemplaVoilà Plus with two arguments, the appropriate part of the ->TA variable (Template Array = cached template markup) and an array with the mininews data. :: 1: // Create list of elements: 2: $elements=''; 3: while($this->internal['currentRow'] = mysql_fetch_assoc($res)) { 4: $elements.=$this->TMPLobj->mergeDataArrayToTemplateArray( 5: $this->TA['sub']['sArchive']['sub']['field_archiveListing']['sub']['element_even'], 6: array( 7: 'field_date' => $this->getFieldContent('datetime'), 8: 'field_header' => $this->pi_list_linkSingle($this->getFieldContent('title'),$this->internal['currentRow']['uid'],1), 9: 'field_teaser' => nl2br(trim(t3lib_div::fixed_lgd($this->getFieldContent('teaser_list'),$this->conf['frontPage.']['teaserLgd']))) 10: ) 11: ); 12: } In this listing you can see that the array with data from mininews has three keys, “field\_date”, “field\_header” and “field\_teaser”. These corresponds with three elements found in the Data Structure XML for the “ARCHIVE LISTING” template: :: 10: 11: array 12:
1
13: 14: Archive Listing container 15: 16: div,table:inner 17: 18: 19: 20: array 21: 22: Element Container, Even 23: 24: *:outer 25: 26: 27: 28: 29: Date 30: News date 31: *:inner 32: 33: 6th August 10:34 34: 29/12 2003 35: 36: 37: 38: 39: 40: Header 41: Header field. 42: *:inner 43: 44: People on mars! 45: Snow in Sydney 46: 47: 48: 49: 50: 51: Teaser 52: Teaser field. 53: *:inner 54: 55: Capthurim Chanaan vero genuit Sidonem primogenitum et Heth Iebuseum quoque 56: 57: 58: This is a part of the Data Structure which is nested inside of :: I point this out because you can see the logic of the variable :: $this->TA['sub']['sArchive']['sub']['field_archiveListing']['sub']['element_even'] in the code listing from this. Basically, if you substitute “sub” with “el” you can almost read that this variable will contain the markup for :: $this->TA['sub']['sArchive']['sub']['field_archiveListing']['sub']['element_even'] **Putting it all together** After having accumulated the list rows (and some other stuff) the values on the outer levels are also composed into a similar API call whose output is finally returned: :: 1: // Wrap the elements in their containers: 2: $out = $this->TMPLobj->mergeDataArrayToTemplateArray( 3: $this->TA['sub']['sArchive'], 4: array( 5: 'field_archiveListing' => $elements, 6: 'field_browseBox_cellsContainer' => $br_elements, 7: 'field_searchBox_sword' => htmlspecialchars($this->piVars['sword']), 8: 'field_searchBox_submitUrl' => htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')), 9: 'field_browseBox_displayRange' => $rangeLabel, 10: 'field_browseBox_displayCount' => $this->internal['res_count'] 11: ) 12: ); 13: 14: return $out; This time you will see that the accumulated content of the list rows ($elements) is added to the key “field\_archiveListing”. For all the other fields you can look them up in the DS as well: :: ... 105: 106: 109: 110: attr 111: 112: Search form action 113: URL of the news-search; Map to the action-attribute of the search form. 114: form:attr:action 115: 116: javascript:alert('Hello, you pressed the search button!');return false; 117: 118: 119: 120: 121: attr 122: 123: Search word field 124: Search word; Map to the forms input-fields value-attribute. 125: input:attr:value 126: 127: Strawberry Jam 128: Jack Daniels 129: Flowers 130: 131: 132: 133: 134: 137: 138: 139: Range 140: Map to position where "x-y" should be outputted (showing which records are displayed) 141: *:inner 142: 143: 1-10 144: 20 to 30 145: 146: 147: 148: 149: 150: Count 151: Map to position where the total number of found records should be outputted. 152: *:inner 153: 154: 123 155: 3402 156: 157: 158: ... Thats all!