为特定的list_type定义TYPO3内容元素布局

3
在TYPO3中,您可以定义自定义布局,专门在“外观>内容元素布局>布局”中显示,用于特定的CType,例如“gridelements_pi1”。如何针对特定的list_type(其中CType为“list”)执行此操作?
代码示例:
TCEFORM {
  tt_content {     
    layout {            
      addItems {
        # layout items for all
      }

      types {
        # CType "gridelements_pi1"
        gridelements_pi1 {
          addItems {
            # layout items only for "gridelements"
          }
        }
        list {
          # is it possible to have
          # layout items only for list_type "XYZ" ?
        }
      }
    }
  }
}
4个回答

1
据我所知,无法将此限制为特定的列表类型。 CType = 故事结束(就像您的示例中那样)
可能的解决方案:如果这是您自己的扩展程序,则可以添加自己的唯一CType,而不仅仅是称其为“列表”。
tt_content_defValues {
  CType = your_own_ctype
  list_type = extname_pluginname
}

是的,似乎没有针对所提到问题的内置解决方案。但现在我会等待接受答案。 - HerrZ

0

正如Mikel已经说过的那样:在typoscript结构中没有更多的选项来配置特殊插件。

但是在当前上下文中,可能可以使用TSconfig中的条件来识别插件类型。
我记得有一次安装中使用了这种方法,但我不记得确切的配置以及这个方法是否仍然适用于更新的TYPO3版本。所以很遗憾,我没有这个案例的工作示例或文档。


0
在 TYPO3 11+ 中,您可以使用 itemsProcFunc 来实现此功能。它允许您为布局选项设置更复杂的条件:
// my_site_package/Classes/Tca/TtContentLayoutOptions.php

class TtContentLayoutOptions
{
    public function addOptions(array &$params): void
    {
        $ttContentEntry = $params['row'];
        $cType = $ttContentEntry['CType'];
        if (is_array($cType)) {
            $cType = $cType[0];
        }

        if ($cType == 'list' && $ttContentEntry['list_type'] == 'XYZ') {
            // Add layout options for list_type "XYZ" here:
            $params['items'][] = [
                'My example layout',
                '100'
            ];
        }

    }
}

注册您的函数:

// my_site_package/Configuration/TCA/Overrides/tt_content.php:

$GLOBALS['TCA']['tt_content']['columns']['layout']['config']['itemsProcFunc'] =
    \MySitePackage\Tca\TtContentLayoutOptions::class .'->addOptions';

这里有一个更"配置化"方法的教程。不幸的是它是德语,但其中包含了一个完整易于理解的代码示例。


-1

这个有效

TCEFORM{
    tt_content{
          layout {     
            types {
                div {
                    addItems {
                         30 = Grey
                    }                    
                }
            }
        }
}

这匹配到的是 ctype,而不是 list_type。 - Mikel Wohlschlegel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接