English English Spanish EspañolKorea한국어
Straker»Company»Blog»2008» Automatically creating folders in Digital Assets based on Site Tree

Automatically creating folders in Digital Assets based on Site Tree

There are times when you want to automatically create a folder in Digital Assets (FMS) manager for each newly added section/page in the site tree. Some implementations of ShadoCMS adopt this as an organizing principle for their digital assets. Implementing this with ShadoCMS is a matter of creating an event handler and assign that event to the onCreate event handler!

Log in to Shado Central and navigate to Object Designer.

Click on the "ShadoMX" package.

Click on the "pages" class within this package.

Select the "Events" tab.

Click on the "afterCreate" event.

Click the "Add" sub-tab and add the following code and click "Update".

<!--- Change the name of the filestore to one you want --->
<cfset sFileStore     = "default">

<!--- This is the UUID of the page being created. Change it any other variable if you need--->
<cfset uPage        = arguments.uuid>

<!--- Change the folder path to a folder that you want to store create page folders in --->
<cfset sFolderPath    = "/mmlibrary">

<!--- Initialize the FMS --->
<cfset oFMS         = application.shado_obj_factory.get("shadomx.apps.fms.fms").init()>
<cfset oFMSContext     = application.shado_obj_factory.get("shadomx.apps.fms.fmscontext").init(filestore=sFileStore)>

<!--- Initialize the site-specific FMS object --->
<cfset oFolder         = createObject("component","#request.siteContext.dsn#.app_templates.objects.FMS.fms_folder").init()>

<!--- Add a folder --->
<cfset oFolder.addFolder(name=uPage,folderpath=sFolderPath)>
 

Click on the "List" tab to verify that the afterCreate assign event has been setup correctly.

To test the event, simply go to the Site Tree and add a page. Once the page is created, a folder whose name is the UUID of the newly created page is created in the default filestore, /mmlibrary folder. 

Obviously this code is application for newly created pages. If you want to follow this for a site tree that already exists, you can use the same logic and customize it to suit you requirements. 


Comments

There are no comments for this page as yet.

Add a comment