Knowledge Base

Working With Custom Hooks: OnRenameAsset

Naming conventions are an often overlooked but very important aspect of organized CMS management. This custom hook can help your team use the correct naming conventions everytime and understand if an asset has been renamed in the past.


In the context of the Ingeniux CMS platform, assets refer to content items like images, PDF documents, and even sometimes code that are stored in the CMS and published out to a publishing target. Assets differ from page types and components – which are created, edited, and managed directly in the CMS Site Tree – in that they are uploaded, or brought into the CMS, from outside of the platform. Once uploaded, they are stored in the Asset Management System (and usually placed into an Asset Schema) where they can be managed, edited in certain ways, and have metadata assigned to them. 

Asset names are used to create the path to the asset and, upon publish, the URL.  

To rename an asset, a user must check the asset out and have the correct set of permissions.  

How To Trigger the Hook  

This method is triggered through the following actions: 

  • Right-Clicking on an Asset, selecting Rename, and completing the dialog. 

When to Use This Custom Hook  

Beyond the built-in controls and settings that Administrators have access to in the CMS, they might be interested in using this hook for things like: 

  • Controlling the asset naming conventions (e.g., filter out special characters, ensure internal procedures are followed). 
  • Preventing the renaming of assets that are essential to other systems. 
  • Renaming companion content to match. 

Considerations 

Assets in the CMS are tracked by their xID, so the name of the asset doesn’t have as much meaning as in a traditional HTML website. Changing the name of an asset automatically provides a redirect to the default URL as well. Custom URLs can be manually added to any asset through the Properties tab.  

Avoid changing the name of an asset content item from within OnRenameAsset to prevent infinite loops and make sure you are carefully distinguishing between the new name and the old name. Developers have often made the mistake of checking the new name against the new name and the hook doesn’t end. 

Example  

Add the Previous Name to the Comments 

This example is a short one. Here we are making sure that the next person to work on the asset is aware that there was a previous name by adding that fact to the comments. This is useful if you have an approval process for asset changes, since the name might not be noticed in the process of checking the metadata and size of the asset. 

The code is concise, the asset object has a comments property for adding in a string. Set the new comment to the string “Previous Name =>" and then add on the old name. 

contentItem.Comments = "Previous Name => "+ oldName; 

Ways to Extend the Functionality Further  

The rename action itself is very concise and not used very often. If you were doing any other actions in this hook, such as preventing special characters, you could also add those facts into this code for the comment. This would let you know that the user had forgotten that they couldn’t use those characters and give you a chance at re-education. 

  • PRODUCT: CMS
  • VERSION: CMS 10
  • RELEASE: 10.x
  • Published: July 24, 2023
  • LAST UPDATED: September 18, 2023
  • Comments: 0

Please login to comment

Comments


There are no comments yet.