Tags, collections and sections
5 February 2018 | 44 views | Tags: Documentation
Tags are essentially "subject labels" that you can apply to other content objects; you can label a content object with as many tags as you want. Associations between tags and content are recorded in the taglink table of the database. Every time a content object is inserted, updated or deleted its associated taglinks are updated automatically, so long as you do this using the insert(), delete() and update() methods in the relevant content handler. Taglinks are represented by the TfTaglink class.
Collections basically function as categories, but they are fully-fledged content objects in their own right. You can assign content to any existing collection using the 'parent' field in the content data entry form. Any kind of content can be assigned to a collection, so mixed sets of content are possible. Collections can be nested by assigning one as the parent of another, thereby creating subcategories.
Tags can also be organised into collections, which is useful if you want to create custom tag select boxes from a subset of tags. To retrieve a collection of tags and build a select box with it call getArbitrarySelectBox():
/** * Prepare a select box from an arbritrary collection of tags. */ // Retrieve tags that are members of a collection with ID 851 (online tags only). $criteria = $tfCriteriaFactory->getCriteria(); $criteria->add($tfCriteriaItemFactory->getItem('parent', 851); $criteria->add($tfCriteriaItemFactory->getItem('type', 'TfTag')); $criteria->add($tfCriteriaItemFactory->getItem('online', 1)); $tagHandler = $contentHandlerFactory->getHandler('tag'); $tagList = $tagHandler->getListOfObjectTitles($criteria); // Prepare the select box using the retrieved tags. Target will be present page (index.php). $tfTemplate->selectAction = 'index.php'; $tfTemplate->selectFilters = $tagHandler->getArbitraryTagSelectBox($cleanTag, $tagList); $tfTemplate->selectFiltersForm = $tfTemplate->render('selectFilters');
Both tags and collections can be used to quickly create sections for a website. By 'section' I mean a logical division of content, perhaps by content type or by subject, that you might include as menu or navigation element.
If you wanted to create a "Publications" section on your website consisting of (say) PDF downloads, you could:
- Create a collection object called "Publications". Both tags and collections display a list of member / child content below their own description, in teaser format.
- Edit the relevant download objects, setting "Publications" as their parent.
- Add a link to the ID of the "Publications" collection in your navigation menu (remember it's as simple as https://yoursite.com?id=42).
- If you would prefer a custom, user-friendly URL such as 'publications.php', that can be achieved by making a copy of /extras/staticpage.php with whatever filename you prefer. Editing the tag or collection ID into the configuration section at the top of the script. Put it in your site root and you are done.
////////// CONFIGURATION ////////// // 1. Enter the ID of the content object you want to display on this page, eg. 10. $id = 10; // 2. Enter the name of the page you want headings and tags to link back to, without extension, eg. 'index'. $targetFileName = 'index'; $tfTemplate->targetFileName = $targetFileName; // 3. Set the page title to whatever you like. $tfTemplate->pageTitle = 'Some page title'; ////////// END CONFIGURATION //////////
Your new section will automatically update itself as you add new content to the Publications collection. Tags work the same way. Static pages with custom URLs also also make good sections, However, you can use any content object.
Copyright, all rights reserved.