从插件模板中检索内容元素字段?

发布于 2025-01-17 23:21:19 字数 244 浏览 4 评论 0原文

我正在修改插件的模板,并且想从内容元素中检索字段。

使用 f:debug 我发现唯一可用的数据来自插件本身,而没有来自内容元素。

有什么方法可以在插件设置中插入我需要的字段吗?

例如。像这样的东西:

plugin.tx_plugin.settings {
    contentUid = TEXT
    contentUid.field = uid
}

I am modifying the template of a plugin, and I want to retrieve a field from the content element.

Using f:debug I see the only data available is from the plugin itself, and none from the content element.

Is there any way I can perhaps insert the field I need in the plugin settings?

eg. something like:

plugin.tx_plugin.settings {
    contentUid = TEXT
    contentUid.field = uid
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜尕妞 2025-01-24 23:21:19

我能想到的最好的方法是使用自定义ViewHelper。类似:

namespace MyVendor\MyExtension\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class ContentUidViewHelper extends AbstractViewHelper
{
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
        return $configurationManager->getContentObject()->data['uid'];
    }
}

在您的流体模板中:

<mynamespace:contentUid />

这将获得内容元素的UID,但是您可以通过这种方式获得任何字段。只需将数据的密钥更改为所需的字段。

The best way I can think of to do this is with a custom ViewHelper. Something like:

namespace MyVendor\MyExtension\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class ContentUidViewHelper extends AbstractViewHelper
{
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
        return $configurationManager->getContentObject()->data['uid'];
    }
}

In your Fluid template:

<mynamespace:contentUid />

This will get the uid of the content element, but you can get any field this way. Just change the key of the data array to the field you need.

为人所爱 2025-01-24 23:21:19

在相应的方法中(例如ListActionshowAction),您可以通过以下方式获取内容元素的数据:

$contentObject = $this->configurationManager->getContentObject();
$this->view->assign('contentObjectData', $contentObject->data);

据我所知,您可以't使用Typoscript获取该数据,但是自从我在控制器中使用上述代码以来,我从来都不需要它。

In the corresponding method (like the listAction or showAction) of the controller you can get the data of the content element in the following way:

$contentObject = $this->configurationManager->getContentObject();
$this->view->assign('contentObjectData', $contentObject->data);

As far as I know, you can't get to that data using typoscript, but I've never needed it anyway since I've been using the above code in the controller.

眉黛浅 2025-01-24 23:21:19

设置没有默认值 stdwrap -type,但只有 string 。因此,您无法将共核用作值。

对于一个(或几个)设置,您可以在方法/班级中进行 stdwrap - 处理:

$settingsAsTypoScriptArray = $this->objectManager->get(TypoScriptService::class)->convertPlainArrayToTypoScriptArray($this->settings);
$contentObj = $this->configurationManager->getContentObject();
if ($contentObj === null) {
  $contentObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}
// now override the values in the settings array with the processed value
$contentUid = (int)$contentObj->stdWrap($settingsAsTypoScriptArray['contentUid'], $settingsAsTypoScriptArray['contentUid.']);

如果您想拥有许多设置,请 stdwrap 查看Ext:新闻。乔治通过” nofollow noreferrer> usestdwrap 配置。

settings do not have stdWrap-type per default, but only string. So you can not use cObjects as values.

For one (or a few) settings, you could do the stdWrap-processing in your method/class yourself:

$settingsAsTypoScriptArray = $this->objectManager->get(TypoScriptService::class)->convertPlainArrayToTypoScriptArray($this->settings);
$contentObj = $this->configurationManager->getContentObject();
if ($contentObj === null) {
  $contentObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}
// now override the values in the settings array with the processed value
$contentUid = (int)$contentObj->stdWrap($settingsAsTypoScriptArray['contentUid'], $settingsAsTypoScriptArray['contentUid.']);

If you wanna have many settings to be stdWraped, have a look into EXT:news. Georg implemented an interesting concept via useStdWrap configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文