Tagger
Created by YJ Tso on Apr 3, 2014. Last edited by John Peca on Feb 17, 2015.
Tags, Categories, and More for MODX!
A robust and performant tag management system. Summary of the many, many features:
- Tested with up to a million tags
- Paginated drop-down and type-ahead for easy tag input
- Combo-box or tag-field input types
- Optionally remove unused tags from the database automatically
- Optionally restrict tag creation to the CMP, versus on input
- Optionally use Auto-Tag cloud for input
Display and list: all tags, tags from specified group(s), omit unused tags, Resources with a given tag, etc. Supplies getResources with a &where condition, so that all the templating and sorting abilities of getResources are at your fingertips.
Installation
Install via Package Management, or download the package from the MODX Extras repository
Tagger FURLs are currently not working when using any resource extensions (.html,...) except /. Please change your extension to / at least on the resource where is TaggerGetResourcesWhere snippet called.
- Content -> Content Types -> HTML (.html) -> /
Groups
After installation you will need to set up some groups. Groups are representing fields that will be added to your Resource panel. Open components menu, find Tagger and go to Groups tab. Add new group.
GROUP OPTIONS:
Option | Required? | Description |
Name | required | Label of the field that will be added to Resource panel |
Description | optional | Description is showed on field hover |
Alias | optional | If not filled, will be generated automatically. Is used in FURLs. |
Field type | required | Tag field - multi select field, Combo box - classic one item select field |
Place | required | Where will be this group rendered. Options are: In tab, Above content, Below content, Bottom page, In TVs section |
Position of Tagger tab in TVs section | optional | If not filled 9999 will be used. Position of Tagger group in TVs tab panel. Use 0 to make Tagger group first. |
Remove unused tags | optional | If set to yes, all tags, that are not assigned to at least one resource will be removed from database. |
Allow new tags from field | optional | If set to yes, users will be able to add new tags from field. Setting to no can be useful for example for list of categories |
Allow blank | optional | If set to no, field will be marked as required and users will have to select at least on tag before saving the Resource |
Allow type | optional | If set to no, users will not be able to type in the field. Clicking to the field will trigger showing list of available tags. |
Show autotag | optional | If set to yes, all tags will be displayed below the field. Users will be bale to click on them to select/unselect. Available only for Tag field. |
Hide input | optional | Can be used only with Show autotag enabled. Will hide the input field and assign button, so users will be able only click on existing tags. |
Tag limit | optional | Will limit number of tags that users can select. Setting to 0 will allow to select infinite number of tags. |
Show for Templates | required | Comma separated list of template IDs for that should be this group displayed. |
Changing labels of Tagger places
In system settings under Tagger namespace are available those settings: tagger.place_in_tab_label, tagger.place_tvs_tab_label, tagger.place_above_content_label, tagger.place_below_content_label, tagger.place_bottom_page_label
You can change their value to text or a lexicon key. If you want to have different name based on Resource Template, you can use following notation:
1==Label For Template with ID 1||2==Label For Template with ID 2
Default label: tagger.tab.label
Basic Usage
TaggerGetTags
This Snippet allows you to list tags for resource(s), group(s) and all tags
PROPERTIES:
Property | Type | Required? | Description | Default |
&resources |
string | optional |
Comma separated list of resources for which will be listed Tags |
|
&groups |
string |
optional |
Comma separated list of Tagger Groups for which will be listed Tags |
|
&rowTpl |
string |
optional |
Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered |
|
&tpl_N | string | optional | Name of chunk that will be used for every Nth tag | |
&outTpl |
string |
optional |
Name of a chunk that will be used for wrapping all tags. If no chunk is given, tags will be rendered without a wrapper. Placeholder: [[+tags]] |
|
&separator |
string |
optional |
String separator, that will be used for separating Tags |
|
&limit | int | optional | Limit number of returned tag Tags | 0 |
&offset | int | optional | Offset the output by this number of Tags | 0 |
&totalPh | string | optional | Placeholder to output the total number of Tags regardless of &limit and &offset | tags_total |
&target |
int |
optional |
An ID of a resource that will be used for generating URI for a Tag. If no ID is given, current Resource ID will be used |
current resource |
&showUnused |
int |
optional |
If set to 1, Tags that are not assigned to any Resource will be included to the output as well |
0 |
&toPlaceholder | string | optional | If set, output will return in placeholder with given name | |
&showDeleted | int | optional | If 1 is set, Tags that are assigned only to deleted Resources will be included to the output as well | 0 |
&showUnpublished | int | optional | If 1 is set, Tags that are assigned only to unpublished Resources will be included to the output as well | 0 |
&contexts | string | optional | If set, will display only tags for resources in given contexts. Contexts can be separated by a comma | |
&wrapIfEmpty | int | optional | If set, outTpl will be used even if there will be no tags to display. | 1 |
&translate | int | optional | If set, group_name_translated and group_description_translated will be added as a placeholders to rowChunk | 0 |
OUTPUT PLACEHOLDERS AND EXAMPLE VALUES:
[[+id]] => 1 [[+tag]] => News<br>[[+alias]] => news [[+group]] => 3 [[+group_id]] => 3 [[+group_name]] => Media Type [[+group_field_type]] => tagger-combo-tag [[+group_allow_new]] => 0 [[+group_remove_unused]] => 0 [[+group_allow_blank]] => 1 [[+group_allow_type]] => 0 [[+group_show_autotag]] => 0 [[+group_show_for_templates]] => 21 [[+cnt]] => 1 [[+uri]] [[+idx]] = Number starting from one for each tag
EXAMPLE USAGE:
// Get tags for all resources, including unused tags [[TaggerGetTags? &showUnused=`1`]] // Get tags from groups 1 and 3 for all resources [[TaggerGetTags? &groups=`1,3` &rowTpl=`tag_links_tpl`]] // Get tags for current resource [[!TaggerGetTags? &resources=`[[*id]]` &rowTpl=`tag_links_tpl`]] // Get tags for current resource in getResources tpl [[!TaggerGetTags? &resources=`[[+id]]` &rowTpl=`tag_links_tpl`]]
How to translate groups
Let's say we have a group with name Tags and alias tags. To translate name and/or description of this group, we will have to create new lexicons entries in a specific format.
- Open lexicon management
- Select Tagger namespace and custom topic
- Add new lexicon entry to this namespace and topic with a key: tagger.custom."group_alias" (in this example it will be tagger.custom.tags)
- If you want to translate description add one more lexicon entry with key: tagger.custom."group_alias"_desc (in this example it will be tagger.custom.tags_desc)
- If you want to use those translations also on frontend, call TaggerGetTags with option &translate=`1` ([[TaggetGetTags? &translate=`1`]]), new placeholders (group_name_translated, group_description_translated) will be available
TaggerGetResourcesWhere
This snippet generate SQL Query that can be used in WHERE condition in getResources snippet
PROPERTIES:
Property | Type | Required? | Description | Default |
&tags | string | optional | Comma separated list of Tags for which will be generated a Resource query. By default Tags from GET param will be loaded | |
&groups | string | optional | Comma separated list of Tagger Groups. Only from those groups will Tags be allowed | |
&where | string | optional | Original getResources where property. If you used where property in your current getResources call, move it here | |
&likeComparison | int | optional | If set to 1, tags will compare using LIKE | 0 |
&matchAll | int | optional | If set to 1, resource must have all specified tags. | 0 |
EXAMPLE USAGE:
[[!getResources? &where=`[[!TaggerGetResourcesWhere? &tags=`Books,Vehicles` &where=`{"isfolder": 0}`]]`]]
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).