SkyBlue
SkyBlue

Reputation: 277

How to override the ftl in alfresco

I'm new to alfresco and using Alfresco 6. I am trying to override colleagues.get.html.ftl file so I can change the display of Site members dashlet. Original ftl has the following code snippet:

 <div class="person">
      <#-- LIST - ITEM - PERSON -->
      <@markup id="list-item-person">
          <h3><a href="${url.context}/page/user/${m.authority.userName?url}/profile" class="theme-color-1">${m.authority.firstName?html} <#if m.authority.lastName??>${m.authority.lastName?html}</#if></a> 
          </h3>
      </@markup>

      <#-- LIST - ITEM - ROLE -->
      <@markup id="list-item-role">
           <div>${msg("role." + m.role)}</div>
      </@markup>
 </div>

Instead of firstName and lastName I just want to display the userName.

Here's what I have done.

  1. I have copied the original code to a file named colleagues.get.html.ftl
  2. I have modified the html.

I was assuming this would override the original file. However my changes are not getting reflected when I restart server. How to correct this?

Upvotes: 0

Views: 537

Answers (1)

Jeff Potts
Jeff Potts

Reputation: 10538

First, I'll assume you are using the Docker- and Maven-based Alfresco SDK 4.0.0. It makes doing this kind of customization much more productive.

The goal is to customize an out-of-the-box web script template and keep it in your own path to avoid problems when upgrading later. To do that, copy the colleagues.get.html.ftl into your project, in a path that you choose. For example, in my project I'll use alfresco-share-example-share/src/main/resources/alfresco/web-extension/site-webscripts/com/metaversant/alfresco/dashlets/colleagues.get.html.ftl.

Next, you need to tell Share that you are overriding the template and where to find yours. You do that by creating a Share extension file. I'll name mine colleague-example.xml and place it in alfresco-share-example-share/src/main/resources/alfresco/web-extension/site-data/extensions/colleague-example.xml with the following content:

<extension>
  <modules>
    <module>
      <id>Colleague Example</id>
      <version>1.0</version>
      <auto-deploy>true</auto-deploy>
      <customizations>
        <customization>
            <targetPackageRoot>org.alfresco.components.dashlets</targetPackageRoot>
            <sourcePackageRoot>com.metaversant.alfresco.dashlets</sourcePackageRoot>
        </customization>
      </customizations>
    </module>
  </modules>
</extension>

Finally, edit your version of the template. We're going to tell Alfresco to replace the @markup with an id of "html" with ours. So change:

<@markup id="html">

to:

<@markup id="html" target="html" action="replace" scope="global"> 

Next, you want to replace first name and last name with just the username, so change:

<h3><a href="${url.context}/page/user/${m.authority.userName?url}/profile" class="theme-color-1">${m.authority.firstName?html} <#if m.authority.lastName??>${m.authority.lastName?html}</#if></a></h3>

to:

<h3><a href="${url.context}/page/user/${m.authority.userName?url}/profile" class="theme-color-1">${m.authority.userName?html}</a></h3>

Now run the project with ./run.sh build_start. Your Docker images will fire up and you'll see that the Site Members dashlet uses username instead of first name and last name.

If you need to tweak it, make a change, then run ./run.sh reload_share to build and restart just the Share container.

When you are ready to deploy, run mvn install to create a Share AMP you can deploy on your server.

Upvotes: 1

Related Questions