Sitefinity ASP.NET CMS - Content Management System

KB Article

Home >  Support >  Knowledge Base >  KB Article
How to enable categories in the Images & Documents module - ID#957
Rating:
Last Modified: 4/4/2008
Related categories: Modules;

Article information

Article relates to

 3.2

Created by

 Vassil Daskalov


By default, categories are disabled for the Images & Documents module. This, however, does not mean that they cannot be used within the module. When we first started building the module we implemented categories for it. It seemed pretty logical as this functionality comes with the Generic Content module from which the Images & Documents inherit. However, on the module’s completion, we took a more realistic look at what had been done. We decided to remove categories as there were already three kinds of organization - libraries, tags and categories - and two of them seemed to overlap as functionality.
So, the categories controls in the administration ended up as not required and we removed them from the code after the release of Sitefinity 3.2 Beta.

Enabling categories is mostly a matter of knowing the control IDs.
Here is what to do to have them back in the Images & Documents module. 

1. Declare a Category meta field for the Libraries module in the application web.config file:

<cmsEngine defaultProvider="Generic_Content">  
 <metaFields>  
  ...  
  <add key="Libraries.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>  
  ...  
 </metaFields>  
</cmsEngine>  

2. Add the meta field name to the appropriate library type.
    In this example, we want the items in the Image, Document and Custom library types to have the meta field.

<libraries defaultGenericProvider="Libraries">  
  <libraryInfo>  
    <add name="Image" … metaKeys="Category, Author, AlternateText, Extension, Name, Height, Width, Size, Category"></add>  
    <add name="Document" … metaKeys="Category, Author, Description, Extension, Name, Size, Category"></add>  
    <add name="Custom" … metaKeys="Category, Author, Description, Extension, Name, Size, Category"></add>  
  </libraryInfo>  
</libraries> 

3. In the ~/Sitefinity/Admin/ControlTemplates/Libraries/CommandPanel.ascx template, add the link as shown below.
This will insert a link similar to the one for managing Tags in the left pane.

<dt id="cat">  
   <asp:LinkButton ID="categoriesButton" runat="server" Text="Categories"></asp:LinkButton>   
</dt> 

4. Add the CategoriesField control to the following templates:
   ~/Sitefinity/Admin/ControlTemplates/Libraries/ControlPanelEdit.ascx
  
~/Sitefinity/Admin/ControlTemplates/Libraries/ControlPanelEdit_Image.ascx

This will enable you to add and change categories for a given item. 
Make sure you insert this control inside the ContentMetaFields control declaration:

<sfGCn:ContentMetaFields ID="editMetaFields" runat="server">  
  ...  
   <fieldset class="set">  
      <ol class="setIn clearfix">  
         <li class="catSel">  
            <asp:Label ID="Label1" AssociatedControlID="Category" runat="server">  
            <asp:Literal ID="Literal1" runat="server" Text="Category"></asp:Literal>  
            <em id="Em1" runat="server"></em></asp:Label>  
            <sfCtg:CategoriesField ID="Category" runat="server"/>  
         </li>  
      </ol>  
   </fieldset>  
  ...  
</sfGCn:ContentMetaFields> 

After completing these steps, the admin part of the Images & Documents module should look like this:



Categories will look like this when you open an item for editing:



The following example demonstrates how to use categories in public controls. It uses the ImageGallery control when set to show images in List & Page mode. 
All you need to do is add a Label with ID equal to "Category" in the ~/Sitefinity/ControlTemplates/Libraries/GalleryListViewItemTemplates.ascx template like this:

<li id="CategoryWrap" runat="server">  
   <strong><asp:Literal runat="server" Text="Category:"></asp:Literal></strong>  
   <asp:Label runat="server" ID="Category"></asp:Label>  
</li> 

The public control will render like this:



The template changes that should be made for the other modes are analogical. You can find the modified templates in the attached file. It also contains the application web.config and the respective admin and public files.

Article Files

  • CategoriesForLibraries.zip



  • Article Comments

    Josh Morales, 10/28/2008
    wouldn't it be a better idea to associate the library as a whole with the category? that way multiple libraries could be filtered to specific subpages. for example, sub page A would show libraries that match category A. sub page B would have libraries matching category B.

    Telerik Admin, 10/29/2008
    It will probably be.. We will have to think about the usability of this approach though.


    Please Sign In to rate this article or to add it to your favorites.