Creates a tag field, similar to how a ListBoxField looks.
Creates a tag field, similar to how a ListBoxField looks.
By Stan Hutcheon - Bigfork Ltd
composer require "stnvh/silverstripe-taggedfield" "~1"
Clone this repo into a folder called taggedfield
in your silverstripe installation folder.
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
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem