stnvh / silverstripe-taggedfield
Creates a tag field, similar to how a ListBoxField looks.
Installs: 917
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 3
Open Issues: 5
Type:silverstripe-module
Requires
- composer/installers: ~1.0
This package is not auto-updated.
Last update: 2024-10-22 03:39:53 UTC
README
Creates a tag field, similar to how a ListBoxField looks.
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