numero2 / contao-tags
为单个元素分配标签的可能性。
0.2.9
2024-08-16 11:03 UTC
Requires
- contao/core-bundle: ^4.13 || ^5.0
- symfony/console: ^5.0 || ^6.0
- symfony/dependency-injection: ^5.0 || ^6.0
Requires (Dev)
- contao/manager-plugin: ^2.0
Suggests
- contao/calendar-bundle: Enables tagging of events
- contao/news-bundle: Enables tagging of news
README
关于
为单个元素分配标签的可能性。
系统要求
安装与配置
- 通过 Contao 管理器或 Composer 安装(
composer require numero2/contao-tags
)
新闻
-
将以下代码片段添加到您的
news_(full|latest|short|simple).html5
模板中<?php if( $this->tags ): ?> <div class="tags"> <?php foreach( $this->tags as $tag ): ?> <?= $tag; ?> <?php endforeach; ?> </div> <?php endif; ?>
-
配置您的
新闻列表
或新闻阅读器
前端模块,并设置标签重定向页面
(可选) -
此外,将
新闻标签云
模块添加到您的页面的任何位置
事件
-
将以下代码片段添加到您的
event_(full|list|teaser|upcoming).html5
模板中<?php if( $this->tags ): ?> <div class="tags"> <?php foreach( $this->tags as $tag ): ?> <?= $tag; ?> <?php endforeach; ?> </div> <?php endif; ?>
⚠️ 注意:Contao 不提供任何用于 Eventreader 模块的 Hooks,因此我们需要在模板的开头添加一些逻辑来正确解析标签。
<?php use Contao\ModuleEventReader; use Contao\ModuleModel; use Contao\System; $moduleModel = ModuleModel::findOneById(69); // replace with the ID of your actual EventReader module $module = new ModuleEventReader($moduleModel); $tagListener = System::getContainer()->get('numero2_tags.listener.events'); $event = $tagListener->parseEvent($this->arrData, $module); $this->tags = $event['tags']; $this->tagsRaw = $event['tagsRaw']; ?>
-
配置您的
事件列表
或事件阅读器
前端模块,并设置标签重定向页面
(可选) -
此外,将
事件标签云
模块添加到您的页面的任何位置
插入标签
此扩展程序包含一些插入标签,可用于链接到只显示匹配标签条目的页面。
链接的更健壮方式是使用标签的 ID 而不是其名称(可以在 系统 › 标签
下更改)。因此,您可以使用 {{tag_link::1::foo}}
,也可以写成 {{tag_link::1::69}}
(假设 foo
的 ID 是 69)。
开发者
在您的扩展程序中集成标签字段
如果您想在自己的数据容器中使用标签字段,可以通过以下方式定义字段:
$GLOBALS['TL_DCA']['tl_my_extension']['fields']['my_tags'] = [ 'exclude' => true , 'inputType' => 'select' , 'foreignKey' => 'tl_tags.tag' , 'options_callback' => ['numero2_tags.listener.data_container.tags', 'getTagOptions'] , 'load_callback' => [['numero2_tags.listener.data_container.tags', 'loadTags']] , 'save_callback' => [['numero2_tags.listener.data_container.tags', 'saveTags']] , 'eval' => ['multiple'=>true, 'size'=>8, 'tl_class'=>'clr long tags', 'chosen'=>true] , 'sql' => "blob NULL" , 'relation' => ['type'=>'hasMany', 'load'=>'eager'] ];
foreignKey
、options_callback
和save_callback
是必填项。在eval
部分我们添加了一个名为tags
的类 - 这也是JavaScript处理所需的。在eval
中还可以定义一些其他选项。