You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you wanted to link blog tags to blog posts, you might override `getCMSFields` with the following field:
37
+
If you wanted to link blog tags to blog posts, you might override [`DataObject::getCMSFields()`](api:SilverStripe\ORM\DataObject::getCMSFields()) with the following field:
26
38
27
39
```php
28
40
$field = TagField::create(
29
-
'BlogTags',
30
-
'Blog Tags',
31
-
BlogTag::get(),
32
-
$this->BlogTags()
41
+
'BlogTags',
42
+
'Blog Tags',
43
+
BlogTag::get(),
44
+
$this->BlogTags()
33
45
)
34
-
->setShouldLazyLoad(true) // tags should be lazy loaded
35
-
->setCanCreate(true); // new tag DataObjects can be created
46
+
// tags should be lazy loaded
47
+
->setShouldLazyLoad(true)
48
+
// new tag DataObjects can be created
49
+
->setCanCreate(true);
36
50
```
37
51
38
52
**Note:** This assumes you have imported the namespaces class, e.g. `use SilverStripe\TagField\TagField;`.
39
53
40
54
This will present a tag field, in which you can select existing blog tags or create new ones. They will be created/linked after the blog posts are saved.
41
55
42
-
###StringTagField
56
+
## StringTagField
43
57
44
58
You can also store string-based tags, with the following field type:
summary: Provides a custom form field for adding tags to content, supporting either related data objects or simple string-based tags
4
+
icon: tags
5
+
---
6
+
7
+
# TagField
8
+
9
+
The TagField module provides a custom form field for adding tags to content. It supports creating tags as related data objects or as a simple comma-separated list of strings.
0 commit comments