请记住,您可以在 FlexForm 中设置 displayMode。每个以 settings. 为前缀的 FlexForm 属性都将在 {settings} 数组中可用。只需在ext_tables.php 中配置 FlexForm:
$pluginSignature = str_replace('_','',$_EXTKEY) . '_pi1';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForm/flexform_pi1.xml');
然后将 FlexForm XML 添加到配置的路径中:
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Configuration</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.displayMode>
<TCEforms>
<exclude>0</exclude>
<label>Display mode</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">Neat</numIndex>
<numIndex index="1">1</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Clean</numIndex>
<numIndex index="1">2</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</settings.displayMode>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
在本例中,添加了一个带有“整洁”和“干净”两个选项的选择框。
然后您可以在 Fluid 模板中使用它(如果您有两种以上的模式,您也可以使用 SwitchViewHelper 而不是 if 构造):
<f:if condition="{settings.displayMode} == 1">
<f:then>
<f:render partial="Neat/List" arguments="{_all}" />
</f:then>
<f:else>
<f:render partial="Clean/List" arguments="{_all}" />
</f:else
</f:if>
请记住,您可以嵌套分部,因此在分部中有分部是没有问题的。因此,只需为每个视图使用部分视图。
如果你想让它看起来不那么老套,你可以给显示模式一个说话的价值:
<numIndex index="0" type="array">
<numIndex index="0">Neat</numIndex>
<numIndex index="1">Neat</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Clean</numIndex>
<numIndex index="1">Clean</numIndex>
</numIndex>
那你就可以用 this 像这样调用局部了
<f:render partial="List/{settings.displayMode}" arguments="{_all}" />
并以这种方式摆脱 if 构造。