如何在TYPO3中以不同的布局显示前端插件?

问题描述 投票:0回答:2

我有一个TYPO3前端插件,现在我想要两种不同的方式来显示“列表”控制器。我怎样才能做到这一点?

typo3 typo3-7.6.x
2个回答
2
投票

您需要使用flexform作为前端插件,如下所示。

在你的ext_tables.php文件中。

//extenstion name
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);

//plugin integration
$frontendpluginName = 'Plugin name';
$pluginSignature = strtolower($extensionName) . '_'.strtolower(
    $frontendpluginName
);

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
    $pluginSignature,
    'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/configure.xml'
);

现在在这条路径configure.xml上创建/Configuration/FlexForms/文件

<T3DataStructure>
    <sheets>
        <!--
            ################################
              SHEET General Settings
            ################################
        -->
        <sDEF>
            <ROOT>
                <TCEforms>
                    <sheetTitle>General</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <!-- View -->
                    <settings.layout>
                      <TCEforms>
                        <label>Select Frontend Layout</label>
                        <config>
                          <type>select</type>
                          <items>
                            <numIndex index="0">
                              <numIndex index="0">Layout 1</numIndex>
                              <numIndex index="1">1</numIndex>
                            </numIndex>
                            <numIndex index="1">
                              <numIndex index="0">Layout 2</numIndex>
                              <numIndex index="1">2</numIndex>
                            </numIndex>
                          </items>
                          <size>10</size>
                          <minitems>0</minitems>
                          <maxitems>1</maxitems>
                          <suppress_icons>1</suppress_icons>
                        </config>
                      </TCEforms>
                    </settings.layout>
                </el>               
            </ROOT>
        </sDEF>
    </sheets>
</T3DataStructure>

现在在前端模板文件中使用此值,如下所示。

<f:if condition="{settings.layout} == 1">
  <f:then>
    Layout 1 html
  </f:then>
  <f:else>
    Layout 2 html
  </f:else>
</f:if>

1
投票

我有一段时间没有使用它,所以我不是100%这仍然是相关的,API文档建议您仍然可以这样做:

public function listAction() {

  {your_code}

  $this->view->setTemplatePathAndFilename(
          'typo3conf/ext/' .
          $this->request->getControllerExtensionKey() .
          '/{path_to}/OtherTemplate.html');

  $this->view->assign(...);

}

如果需要在每个插件基础上进行切换,请通过读取配置变量来决定使用哪个模板。

© www.soinside.com 2019 - 2024. All rights reserved.