Topics

Adding Tags Support to a Module

How to integrate Exponent tags into a module. 

1. Update the Model by adding tags to the $attachable_item_types array.  Otherwise, the tags never get attached to the item.

'content_expTags'=>'expTag'

2. Update the item ‘edit’ template by adding the tags edit box (assuming the item is referred to as $record), but ensure it is within a 'yui3-skin-sam' class to prevent a transparent background:

 {if !$config.disabletags}
     {control type="tags" value=$record}
 {/if}

3. The controller MUST use or call the expController::update() method to process tags, otherwise, if you have a class update method which does not call parent::update(), you’ll need to add this code.

     if (array_key_exists('expTag',$this->params)&&!empty($this->params['expTag'])) {
         if (isset($this->params['id'])) {
             $db->delete('content_expTags', 'content_type="'.(!empty($this->params['content_type'])?$this->params['content_type']:$this->basemodel_name).'" AND content_id='.$this->params['id']);
         }
         $tags = explode(",", trim($this->params['expTag']));
         unset($this->params['expTag']);
         foreach($tags as $tag) {
                if (!empty($tag)) {
                    $tag = strtolower(trim($tag));
                    $tag = str_replace('"', "", $tag); // strip double quotes
                    $tag = str_replace("'", "", $tag); // strip single quotes
                    $expTag = new expTag($tag);
                    if (empty($expTag->id)) $expTag->update(array('title'=>$tag));
                    $this->params['expTag'][] = $expTag->id;
                }
         }
    }

4. The item assigned tags can easily be displayed

• If you loop through the $page->records as $record, you can use something like this code to parse/display the tags

{tags_assigned record=$record}
Loading Help