如何在TYPO3 6.x中快速创建自定义内容元素 [英] How to quickly create custom content elements in TYPO3 6.x

查看:92
本文介绍了如何在TYPO3 6.x中快速创建自定义内容元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TYPO3 6.x中,快速创建自定义内容元素的简单方法是什么?

In TYPO3 6.x, what is an easy way to quickly create custom content elements?

一个典型的例子(也许是推荐书):

A typical example (Maybe for a collection of testimonials):

在后端(带有足够的标签):

In the backend (with adequate labels):

  • 图片
  • 输入字段
  • 文本区域

渲染时:

  • 图像调整为xy
  • 输入封装在h2中
  • textarea通过parseFunc并包装在更多标记中

理想情况下,这些将在页面模块中以cType的形式提供,但至少在列表模块中可用. 并使用流畅的模板.

Ideally, these would be available in the page module as cType, but at least in the list module. And use fluid templates.

我的问题:

  • 在另一个CMS中,我习惯于同时将内容项目模板应用于BE和FE(您编写该模板的工作方式,然后有一个针对该类型的后端项目)内容元素)-但这不是流畅的工作原理-还是可以做到?

  • From another CMS I am used to content item templates being applied to the BE and the FE at the same time (you write the template for what it should do, and then there's a backend item just for that type of content element) - but that's not how fluid works - or can it be done?

是否有扩展程序可以处理此类自定义内容元素(Templavoila除外)?

Is there an extension that would handle such custom content elements (other than Templavoila)?

还是我必须为每个此类字段类型创建自定义extbase/fluid扩展?

Or do I have to create a custom extbase/fluid extension for each such field type?

并且,顺便说一句:对于新的extbase kickstarter,是否有推荐的教程?我被所有领域建模的东西吓到了.

And, by the way: is there a recommendable tutorial for the new extbase kickstarter? I got scared away by all that domain modelling stuff.

推荐答案

令人恐惧的领域建模工作可能是您最好的选择:)

That scaring domain modeling stuff is probably best option for you :)

使用FE插件创建扩展,该扩展可根据需要保存并显示数据,因此可以将其放置为插入插件".可以将该插件添加为自定义CType,我将为您找到一个示例,但是稍后.

Create an extension with FE plugin which holds and displays data as you want, so you can place it as a "Insert plugin". It's possible to add this plugin as a custom CType and I will find a sample for you, but little bit later.

请注意,您无需创建其他模型即可存储所需的数据,例如.在FlexForm中.

Note, you don't need to create additional models as you can store required data ie. in FlexForm.

让我们考虑您有一个扩展键为hello的扩展,其中包含具有listsingle操作的News控制器.

Let's consider that you have an extension with key hello which contains News controller with list and single actions in it.

在您的ext_tables.php中,您已经注册了FE插件:

In your ext_tables.php you have registered a FE plugin:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin($_EXTKEY, 'News', 'Scared Hello News');

工作正常后,只需在ext_localconf.php中的configurePlugin方法中添加第五个参数,就可以将其添加到内容类型列表中(在TCA中可用):

When it's working fine you can add it to the list of content types (available in TCA) just by adding fifth param to the configurePlugin method in your ext_localconf.php:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'TYPO3.' . $_EXTKEY,
    'News',
    array('News' => 'list, show'),
    array('News' => ''),
    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT // <- this one
);

下一部分(基于

Next part (basing on this site) is adding your plugin to the New Content Element Wizard as noticed in TYPO3 Wiki since TYPO3 ver. 6.0.0 changed a little, so easiest way is adding something like this into your ext_tables.php:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:hello/Configuration/TypoScript/pageTsConfig.ts">');

并在/typo3conf/ext/hello/Configuration/TypoScript/pageTsConfig.ts文件中写入以下内容:

and in /typo3conf/ext/hello/Configuration/TypoScript/pageTsConfig.ts file write add this:

mod.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
    icon = gfx/c_wiz/regular_text.gif
    title = Scared Hello News
    description = Displays Scared News
    tt_content_defValues.CType = hello_news
}

# Below the same for TemplaVoila
templavoila.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
    icon = gfx/c_wiz/regular_text.gif
    title = Scared Hello News
    description = Displays Scared News
    tt_content_defValues.CType = hello_news
}

请注意,正确的键tx_hello_news应该是小写的tx_$_EXTKEY和插件名称的组合-在registerPlugin方法中使用.

Note that proper key tx_hello_news should be combination of lowercased tx_, $_EXTKEY and plugin name - used in registerPlugin method.

无聊的人可以在这里停下来;)

以上步骤将导致您的元素的TCA中没有可用的典型字段,因此您需要复制某些内容或创建自己的内容.要查看其工作原理,请看一些示例,在左侧菜单的后端中,选择ADMIN TOOLS> Configuration> TCA> tt_content> types

Above steps will cause that no typical fields will be available in the TCA for your element, so you need to copy something or create own. To see how it works just see some sample, in the backend in left menu choose ADMIN TOOLS > Configuration > TCA > tt_content > types

您将在系统中找到所有类型,选择最需要的类型并将其[showitem]节点复制到您自己的节点中.再次在ext_tables.php中添加以下PHP数组:

There you'll find all types in the system, choose the most required and copy its [showitem] node into your own. Again in ext_tables.php add this PHP array:

$TCA['tt_content']['types']['hello_news']['showitem'] = $TCA['tt_content']['types']['textpic']['showitem'];

再次:hello_news是小写的$_EXTKEY和FE插件名称的组合...

Again: hello_news is combination of lowercased $_EXTKEY and FE plugin name...

当然,如果需要的话,您可以组成一组完全自己的字段,并通过自定义字符串一一列出:

Of course if it's required you can compose quite own set of fields, one by one by custom string:

$TCA['tt_content']['types']['hello_news']['showitem'] = '--palette--;LLL:EXT:cms/locallang_ttc.xml:palette.general;general, --palette--;LLL:EXT:cms/locallang_ttc.xml:palette.header;header';

访问Extbase Controller中的字段:

幸运的是,这是最简单的部分,因为您可以将其作为数组进行访问:

Access the fields in Extbase Controller:

Fortunately is easiest part as you can just access it as an Array:

$currentTtContent = $this->configurationManager->getContentObject()->data;
$header = $currentTtContent['header'];
debug($currentTtContent);
debug($header);

这篇关于如何在TYPO3 6.x中快速创建自定义内容元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆