Since version 4.6.0, Tags (topics) and Hashtags can be used at the same time. So, we prepare this tutorial to integrate your app with both of them.
Note: we will use the To Do List app as an example for this tutorial.
h2. Tags
Scope
: only in the app.Related Setting
: Enable Tags (tag.enable_tag_support) - Enable this option if you wish to allow tags on the site to create topics for the item being added.
How to use?
- Render the field to add
Tags
for your item in add/edit form
{if Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')} {module name='tag.add' sType='todo'} {/if}
In controller of Edit page, we need to get tags list of edited item
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) { $todo['tag_list'] = Phpfox::getService('tag')->getForEdit('todo', $id); }
- Add/Update tags list when adding/editing item
// Add this php code in service add if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) { if (isset($aVals['tag_list']) && ((is_array($aVals['tag_list']) && count($aVals['tag_list'])) || (!empty($aVals['tag_list'])))) { Phpfox::getService('tag.process')->add('todo', $iItemId, Phpfox::getUserId(), $aVals['tag_list']); } }
// Add this php code in service update if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) { if (Phpfox::isModule('tag') && isset($aVals['tag_list']) && !empty($aVals['tag_list'])) { Phpfox::getService('tag.process')->update('todo', $aVals['task_id'], $aVals['user_id'], $aVals['tag_list']); } }
- Display tags lists of item in Detail page
// Add this php code in controller of detail page to get tags list if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) { $aTags = Phpfox::getService('tag')->getTagsById('todo', $id); if (isset($aTags[$id])) { $aItem['tag_list'] = $aTags[$id]; } }
<!-- Add this code in view template --> {if isset($aItem.tag_list)} {module name='tag.item' sType='todo' sTags=$aItem.tag_list iItemId=$aItem.task_id iUserId=$aItem.user_id sMicroKeywords='keywords'} {/if}
- To support search by tags, we have to add a callback name:
getTagLink
. This callback will return link to search item by tag of the app. Example:
/** * @return string */ public function getTagLink() { return Phpfox_Url::instance()->makeUrl('to-do-list.tag'); }
- We also have to implement a page for browsing items by tag. For more detail, please check the source code of the sample app To Do List
Hashtags
Scope
: using for entire site. You can support to add hashtags in description of your items.Related Setting
: Enable Hashtags (tag.enable_hashtag_support) - Enable this option if you wish to allow hashtags on the site to create topics for the item being added.
How to use?
- Add/Update hashtags when adding/editing item.
// Add this php code in service add if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) { Phpfox::getService('tag.process')->add('todo', $iItemId, Phpfox::getUserId(), $aVals['description'], true); }
// Add this php code in service update if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) { Phpfox::getService('tag.process')->update('todo', $aVals['task_id'], $aTodo['user_id'], $aVals['description'], true); }
- To show hashtags on your detail page, you need to process your content with template built-in function
parse
:
{$aItem.description|parse}