extbase 扩展中的相同模型、不同模板(和操作)
Same Model, different Templates (and Actions) in extbase extension
我不知道我的扩展设置是否有点古怪。
我有一个模型,但有两个插件,因为我想以不同的方式显示相同的数据。
我的想法是:为 pi1 和 pi2 分配两个不同的 Fluid 模板,所有显示逻辑都在这里完成。但据我现在的了解,没有这样的开关,由于"Convention over configuration",我需要一个单独的pi2控制器,对吗?
现在我在 ext_tables.php 中有这个:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi1',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi2',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
我真的必须通过在此处、控制器和模板目录中重命名 "Institution" 来调整所有内容吗?
我现在就是这样做的。保留一个控制器,只需通过在插件所在的页面上设置一些页面 TS 来分叉模板。
plugin.tx_stellen {
settings {
displaymode = 1
}
}
然后是<f:if condition="{settings.displaymode}==1"></f:if>
不过,这是一种变通方法,因为它对整个页面都有效(我什至根本不需要这三个不同的插件)。直接在扩展中定义 TypoScript "per Plugin" 不行吗?
为了回答您在回答中提出的问题...可以在每个插件基础上配置您的扩展的 TypoScript。只需将带有前导下划线的插件名称添加到您的 TS 密钥中,就像这样
plugin.tx_stellen_pi2 {
settings {
displaymode = 1
}
}
除了使用 if 条件,您还可以设置不同的 TemplateRootPath,以便为 pi2 呈现另一个模板。
请记住,您可以在 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');
然后将FlexFormXML添加到配置的路径中:
<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>
在此示例中,添加了一个包含两个选项 "neat" 和 "clean" 的 select 框。
然后您可以在 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>
然后你可以像这样使用它来调用部分
<f:render partial="List/{settings.displayMode}" arguments="{_all}" />
并以这种方式摆脱 if 结构。
我不知道我的扩展设置是否有点古怪。
我有一个模型,但有两个插件,因为我想以不同的方式显示相同的数据。
我的想法是:为 pi1 和 pi2 分配两个不同的 Fluid 模板,所有显示逻辑都在这里完成。但据我现在的了解,没有这样的开关,由于"Convention over configuration",我需要一个单独的pi2控制器,对吗?
现在我在 ext_tables.php 中有这个:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi1',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi2',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
我真的必须通过在此处、控制器和模板目录中重命名 "Institution" 来调整所有内容吗?
我现在就是这样做的。保留一个控制器,只需通过在插件所在的页面上设置一些页面 TS 来分叉模板。
plugin.tx_stellen {
settings {
displaymode = 1
}
}
然后是<f:if condition="{settings.displaymode}==1"></f:if>
不过,这是一种变通方法,因为它对整个页面都有效(我什至根本不需要这三个不同的插件)。直接在扩展中定义 TypoScript "per Plugin" 不行吗?
为了回答您在回答中提出的问题...可以在每个插件基础上配置您的扩展的 TypoScript。只需将带有前导下划线的插件名称添加到您的 TS 密钥中,就像这样
plugin.tx_stellen_pi2 {
settings {
displaymode = 1
}
}
除了使用 if 条件,您还可以设置不同的 TemplateRootPath,以便为 pi2 呈现另一个模板。
请记住,您可以在 FlexForm 中设置 displayMode。每个以 settings.
为前缀的 FlexForm 属性 都将在 {settings}
数组中可用。只需在 ext_tables.php
:
$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');
然后将FlexFormXML添加到配置的路径中:
<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>
在此示例中,添加了一个包含两个选项 "neat" 和 "clean" 的 select 框。
然后您可以在 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>
然后你可以像这样使用它来调用部分
<f:render partial="List/{settings.displayMode}" arguments="{_all}" />
并以这种方式摆脱 if 结构。