stnvh/silverstripe-taggedfield

创建一个标签字段,类似于ListBoxField的外观。

安装: 917

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 3

开放问题: 5

类型:silverstripe-module

1.0.1 2015-01-19 13:41 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:14:46 UTC


README

Latest Stable Version License

创建一个标签字段,类似于ListBoxField的外观。

Tagged Field

由 Stan Hutcheon - Bigfork Ltd 提供

安装

Composer

composer require "stnvh/silverstripe-taggedfield" "~1"

下载

将此仓库克隆到您的 silverstripe 安装文件夹中的 taggedfield 文件夹中。

使用方法

像其他任何字段一样初始化它。确保您在数据库中有一个 'Text' 项来存储值

<?php

class MyObject extends DataObject {

	private static $db = array(
		'Tags' => 'Text'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();

		$taggedField = TaggedField::create('Tags');

		$fields->addFieldToTab('Root.Main', $taggedField);

		return $fields;
	}

	// To use the tags in the template correctly
	public function Tags() {
		$tags = explode(',', $this->Tags);
		foreach($tags as $i => $tag) {
			$tags[$i] = array('Tag' => $tag);
		}
		return ArrayList::create($tags);
	}

}

在模板中

	<% loop Tags %>
		<span class="tag">{$Tag}</span>
	<% end_loop %>

通过 composer 安装后,您必须执行 /dev/build