A node template in action.

A node template in action.

If you're using Alfresco Enterprise 4.0 and above, you're probably familiar with the Node Templates feature which allows you to place files in the Repository under "Data Dictionary/Node Templates" and have them appear as options in your "Create Content..." menu in Share.

Two clients have asked for this capability with respect to folders. For example, a templated folder would allow users to create a pre-defined set of content, rather than having to create the folder structure manually and then populate it with items from the Node Templates directory. After doing a bit of research, it appears it's been on the docket for inclusion in community but isn't high priority. I took a stab at getting this to work in Enterprise 4.1.5, and the solution appears to be relatively straightforward.

Override the following two webscript controllers by copying the files:

  1. <configRoot>/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/node-templates.get.js
  2. <configRoot>/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/node-templates.post.js

Place the copies in either your<extensionRoot>/alfresco/extension/templates/webscripts/org/alfresco/slingshot/documentlibrary directory, or<configRoot>/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/documentlibrary directory.

Then, modify the copies as follows.


This file populates the "Create Content..." submenu with items from the "Data Dictionary/Node Templates" folder and simply does an XPath query. Change the query as follows to return all items in the Node Templates folder:

/** * Document List Component: Create New Node - get list of available node templates in the Data Dictionary * * This is an overridden core file that returns Folder nodes, in addition to content nodes, for creation * from templates. */ function main() { var nodes = search.selectNodes('/app:company_home/app:dictionary/app:node_templates/*'); return nodes; } model.nodes = main();

This change removes the XPath constraint and simply returns everything in the Node Templates folder. For a production system, I'd recommend specializing this query to be exclusive rather than inclusive, based on your specific requirements. For example, adding the constraint 'or subtypeOf("cm:folder")'.


This file receives the create request and copies the selected node template to the current folder in Share. Modify the last line in the main() function by adding a "true" parameter to the copy() call so that a deep copy is performed. This ensures the folders and files within the templated folder are copied.

/** * Document List Component: Create New Node - create copy of node template in the Data Dictionary * * This is an overridden core file that performs a deep copy of template nodes. */ function main() { // get the arguments - expecting the "sourceNodeRef" and "parentNodeRef" of the source node to copy // and the parent node to contain the new copy of the source. var sourceNodeRef = json.get("sourceNodeRef"); if (sourceNodeRef == null || sourceNodeRef.length === 0) { status.setCode(status.STATUS_BAD_REQUEST, "Mandatory 'sourceNodeRef' parameter missing."); return; } var parentNodeRef = json.get("parentNodeRef"); if (parentNodeRef == null || parentNodeRef.length === 0) { status.setCode(status.STATUS_BAD_REQUEST, "Mandatory 'parentNodeRef' parameter missing."); return; } // get the nodes and perform the copy - permission failures etc. will produce a status code response var sourceNode = search.findNode(sourceNodeRef), parentNode = search.findNode(parentNodeRef); if (sourceNode == null || parentNode == null) { status.setCode(status.STATUS_NOT_FOUND, "Source or destination node is missing for copy operation."); } model.result = sourceNode.copy(parentNode, true); } main();

Restart your Alfresco server and the node-templates webscripts should use the newly overriden controllers to handle folders as well as files in the "Node Templates" directory.

Populating a folder template.

Populating a folder template.

Selecting the Folder Template

Selecting the Folder Template

Loading Conversation