Step by Step guide to Customize Alfresco Share layout dashlets pages and document library
I spent almost a day trying to figure out how to make a custom template (Preset) for my Alfresco site. The whole idea was to avoid the manual steps of recreating everything from scratch everytime I created a site.
My requirement was not to have a new template but to workaround the default template to achieve my goal.
Here are the list of things we will be modifying on the Default Alfresco template:
1] Layout
2] Pages
3] Dashlets
4] Custom folders
My Alfresco server is on Linux thus the article focuses on the Linux folder structure, I am sure it will be very easy on a Windows box too. So here we go...
First and foremost, we navigate to the following location:
tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/presets
This is where the default template file (AKA Preset) is stored. if you run the ls command you should see the presets.xml file
Now you need admin privilege to modify the file. To be on a safe side, lets keep the original file by copying it with the following command:
sudo cp presets.xml presets.xml.original
Now lets being editing our presets.xml file with the command:
sudo vi presets.xml
Search for the following piece of data and notice the underline data:
<pages>
<page id="site/${siteid}/dashboard">
<title>Collaboration Site Dashboard</title>
<title-id>page.siteDashboard.title</title-id>
<description>Collaboration site's dashboard page</description>
<description-id>page.siteDashboard.description</description-id>
<template-instance>dashboard-3-columns</template-instance>
<authentication>user</authentication>
<properties>
<sitePages>[{"pageId":"discussions-topiclist"}, {"pageId":"documentlibrary"} ,{"pageId":"links"},{"pageId":"wiki-page"}]</sitePages>
</properties>
</page>
</pages>
1] Layout
First thing we will change is the layout. I wanted my layout to be 3 columns and thus I changed the template-instance as under:
<template-instance>dashboard-3-columns</template-instance>
You can find reference to the Template-instance here:
tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/template-instances
2] Pages
The next thing to do was to add the list of pages, thus I modified the following:
<sitePages>[{"pageId":"discussions-topiclist"}, {"pageId":"documentlibrary"} ,{"pageId":"links"},{"pageId":"wiki-page"}]</sitePages>
You can find the reference to the pages here:
tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/template-instances
Reference:
activityfeed [Site Activities]
calendar
docsummary [Recently Modified Document]
site-links
site-profile
webview
3] Dashlets
The dashlets was the next thing to modify. Since my layout was 3 columns and I wanted 3 dashlets in each column, I searched for the following pice of data:
<component>
<scope>page</scope>
<region-id>component-1-1</region-id>
<source-id>site/${siteid}/dashboard</source-id>
<url>/components/dashlets/site-profile</url>
</component>
Note the the region-id defines the position of the dashlet:
<region-id>component-1-1</region-id>
I had to create 9 region-ids with name component-1-1, component-1-2, component-1-3, component-2-1....... component-3-3
You can find the reference to the dashlets here:
tomcat/webapps/share/WEB-INF/classes/alfresco/site-data/template-instances
Reference:
blog-postlist
calendar
discussions-topiclist
documentlibrary
links
wiki-page
4] Custom Folder
This took a lot of time and reading through various Alfresco documents. The idea here is to create a dummy site and setup the folder structure as required. Then copy the structure to the Data Dictionary by visiting the Repository and finally creating a javascript file and a rule to run the file. Here it goes:
Create a dummy site, go to document library and setup your folder structure.
Once done, click on Repository - Sites - [your Demo Site Name]
click on the checkbox next to the documentLibrary folder and from the Selected items dropdown select Copy to
Navigate to Repository - Data Dictionary - Space Templates and hit the Copy button
Now navigate to the Repository - Data Dictionary - Space Templates folder and you will see a new folder named documentLibrary. Hover the mouse towards the far right of the folder name and click on Edit Properties
In the window that opens click on All Properties
Copy everything after nodeRef= on the URL. The text should be workspace://SpacesStore/fb6160e9-bc40-41c7-bb35-f93741e250d3
Now open a notepad on your computer and enter the following code
if (document.isContainer) {
var ApplyFolderStructure = search.findNode("workspace://SpacesStore/fb6160e9-bc40-41c7-bb35-f93741e250d3");
ApplyFolderStructure.copy(document,true);
}
Save this file as a .js file. Example: PopulateSiteFromTemplate.js
Next go to Repository - Data Dictionary - Scripts folder and upload this file
Now we need to create a rule to trigger this script.
Go to Repository again and hover the mouse far right on the Sites folder
Click More and select Manage Permissions
Click on Inherit Permissions and then Save
Now click More and select Manage Rule
Give the rule a name
Under When, select 'Items are created or enter this folder'
select 'If all criteria are met'
Select 'Content of type or sub-type' is 'folder'
Under perform Action, select the script you just added.
Enable the Run rule in background option.
Save the rule
Now when you create a new site, all the above modification will be applied to your template.