I use for the T3 Backend a TCA type select in a renderType = selectMultipleSideBySide
Here the TCA Code:
'features' => array(
'label' => 'Zusatz',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'size' => 10,
'minitems' => 0,
'maxitems' => 999,
'items' => array(
array(
'Parkplätze',
'parking'
),
array(
'Freies Wlan',
'wlan'
),
)
)
),
it works fine in the Backend!
But, how can I read the data properly now? I dont now the right way for the Domain/Model.
/**
* Features
*
* @var string
*/
protected $features = '';
/**
* Returns the features
*
* @return string $features
*/
public function getFeatures() {
return $this->features;
}
/**
* Sets the features
*
* @param string $features
* @return void
*/
public function setFeatures($features) {
$this->features = $features;
}
the Debug Code put out: features => 'parking,wlan' (12 chars)
a for each dont work:
<f:for each="{newsItem.features}" as="featuresItem">
{featuresItem}<br />
</f:for>
thanks for help!
You need to explode the string by comma, so you'll be able to iterate them in the loop, there are at least two approaches: one is custom ViewHelper, second (described bellow) is transient field in your model, when you'll get the IDs of features, you need also to "translate" it to human readable label...
In your model that holds the features, add the transient field with getter like in the sample below: (of course you may delete these boring comment in the annotation but you must to keep the
@var
line with proper type!):As mentioned before, you need to get human readable labels for the ID, even if you don't build multi-lingual page translation file are very useful, just in the file
typo3conf/ext/yourext/Resources/Private/Language/locallang.xlf
add items for each feature you have in your TCA select:as you can see id's of the trans-units after the dot are the same as the keys of your features from TCA,
finally all you need to use this in the view is iterating the transient field instead of original one:
After adding new fields into model (even if they're transient) and adding or changing entries in localization files you need to clear the System cache! in 6.2+ this option is available in the install tool (but you can set it available via UserTS under the flash icon).
Note: the pretty same thing can be done with custom ViewHelper, but IMHO transient field is easier.