How to add custom tags to your documents

on 15-Sep-2009 | Comments ( 3 ) Tags: Evolution

In order to properly tag your documents I recommend using a special table that will have all the values you need. By using a table you can easily change the values and also add new ones quite fast.

1. Create a table in your modx database:

In my case the table will be named tags_modx_versions and will have 2 fields id and name

Here's the SQL command for creating this table


Insert the first 2 values: Evolution and Revolution

INSERT INTO `tags_modx_versions` (`id`, `name`) VALUES ('', 'Evolution'), ('', 'Revolution');

At this point we're done with the database stuff.

2. Create the TV

Log in into the Manager and create a new TV. I will name it modxVersion.

Enter a caption/description, select Checkbox for Input Type and paste the following into Input Option Values:

@SELECT name,id FROM tags_modx_versions ORDER BY name

Widget: Delimited List

Delimiter: ,

Before saving the TV you have to select the template you want to use it for.

Click here to see a screen grab.

Display the tags3. Display the tags

At this point if you want to use the TV you will get an ID or a comma separated list of IDs.

To display the names associated with those IDs we have to create a new snippet:

// [[GetModxVersion? &ids=`[*modxVersion*]`]]
$ids = isset($ids) ? $ids : 0;

    $values = array();
    $res = $modx->db->select("name", "tags_modx_versions", "id IN ($ids)", "name ASC");
    while ($row = $modx->db->getRow( $res )) {
        array_push($values, $row['name']);
    return implode(', ', $values);

Call the snippet anywhere in your document like:

[[GetModxVersion? &ids=`[*modxVersion*]` ]]


This was quite a long one, but now you can easily add new tags by using the Insert functionality in phpMyAdmin or your favorite database tool.

Note: A modx module can be created in order to Add or Delete new tags. I will handle this in a future post.

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Posts: 2
Re: How to add custom tags to your documents
Reply #3 on : Mon October 19, 2009, 02:41:13
Hi Cipa,

what are the advantages of this tagging solution to the one of Ditto? The output of this Snippet will be a list of Tags - no links, right? - thanks, jan

keep up the good work :) this site's quickly becoming a great MODx ressource
Posts: 1
Re: How to add custom tags to your documents
Reply #2 on : Mon October 19, 2009, 07:51:13
If you are referring to

I think the only difference is that if you later want to change a tag Eg: Evolution -> Modx Evolution it is easy to do. You only have to edit your table.

Imagine having to change the tag for all the documents. I guess you can do it with sql script but it's not as easy.
Posts: 2
Re: How to add custom tags to your documents
Reply #1 on : Mon October 19, 2009, 14:53:51
ah, okay, i see - thanks!

Quick modx Evolution Tags

  • cached [[snippet]] or uncached [!snippet!]
  • {{chunk}}
  • [+placeholder+]
  • [*resourceField/TV*]
  • [^timing^]
  • [~link~]

Quick modx Revolution Tags

  • [[snippet]]
  • [[$chunk]]
  • [[+placeholder]]
  • [[*resourceField/TV]]
  • [[~link]]
  • [^timing^]
  • [[++systemSetting]]
  • [[%languageStringKey]]
  • all tags can be called un-cached like: [[! snippet]]

Timing Tags (Evo and Revo)

  • [^qt^] - Query time
  • [^q^] - Query count
  • [^p^] - Parse time
  • [^t^] - Total time
  • [^s^] - Source
© modxRULES! 2009-2014