如何在 TYPO3 的 Extbase Frontent 插件中获取根线/面包屑

How can I get a rootline / breadcrumb within an Extbase Frontent Plugin in TYPO3

有没有办法在 TYPO3 9 的 Extbase 前端插件中使用 dataProcessing / MenuProcessor?

我想在插件中构建页面根线。我知道如何在页面上下文或 tt-content 元素中制作它,但我也可以在插件中制作它吗?

我在插件设置中尝试了以下方法,但这不起作用:

plugin.tx_extensions_show {
    view {
        ...
        dataProcessing {
            10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
            10 {
                special = rootline
                special.range = 1|-1
                includeNotInMenu = 1
                as = rootline
            }
        }
    }
}

在您的插件代码中,您可以获取数组中的根行:

// ($MP and $this->context are optional)
$rootline = GeneralUtility::makeInstance(RootlineUtility::class, $uid, $MP, $this->context);
$rootlinePages = $rootline->get();

现在您可以将 $rootlinePages 传递给您的 FLUID 模板。

Hth.

基于 of Loek 在控制器中而不是在流体模板中执行此操作,我找到了自己的解决方案来获取数组中的根线并将其传递给我的 TYPO3 9 流体模板:

    $rootLineUtility = new \TYPO3\CMS\Core\Utility\RootlineUtility($GLOBALS['TSFE']->id);
    $rootline = $rootLineUtility->get();
    $this->view->assign('rootline', $rootline);