stnvh/silverstripe-taggedfield

Creates a tag field, similar to how a ListBoxField looks.

Installs: 520

Dependents: 0

Suggesters: 0

Stars: 1

Watchers: 1

Forks: 3

Open Issues: 5

Type:silverstripe-module

1.0.1 2015-01-19 13:41 UTC

README

Latest Stable Version License

Creates a tag field, similar to how a ListBoxField looks.

Tagged Field

By Stan Hutcheon - Bigfork Ltd

Installation:

Composer:

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

Download:

Clone this repo into a folder called taggedfield in your silverstripe installation folder.

Usage:

Initialize it like any other field. Make sure you have a 'Text' entry in the database to store the values:

<?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);
	}

}

In the template:

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

After installing via composer, you must /dev/build