2

In Alfresco, I have multiple workflows in which i send an email based on certain events. Each e-mail template uses the same layout and design. Therefore, I want to import a "shell" template and pass in different variables based on the type of workflow and event.

// lib/utils.html.ftl
<#macro shell greeting>
   ${greeting}
</#macro>

So as example, I have a task-assignment.ftl template, where I want to import my base template.

// task-assignment.html.ftl
<#import "./lib/utils.html.ftl" as utils>
<#assign greeting="${greeting!'Hello User'}" />
<@utils.shell greeting />

My problem is the value of the path to the file in the Freemarker <#import >.

I can't figure out how to get the path in a format that Freemarker understands and Alfresco can provide.

var file = companyhome.childrenByXPath("/app:company_home/app:dictionary/app:email_templates/cm:test/cm:utils.html.ftl");


logger.log(file[0].url) => /d/d/workspace/SpacesStore/08234083-23948234-2349834/utils.html.ftl

<#import file as utils>

Caused by: freemarker.core._MiscTemplateException: Error reading imported template string://d/d/workspace/SpacesStore/08234083-23948234-2349834/utils.html.ftl

Does anyone know, how to get the path to the file in a format that Freemarker is happy with and Alfresco is able to provide?

I'm using Freemarker version 2.3.20 and Alfresco Community version 6.1.2.

1 Answers1

0

You can use the import your base template if that's also in your classpath. See the below code snippet.

<#import "../refresh_script.html.ftl" as refresh>

<div id="Rec1" class="info">
    <div id="Ctrl_top_read" class="titremontre hd" ><img src="${url.context}/images/deployment_report.gif" alt="icon"><span class="titlebox">${msg("mostread")}</span></div>
    <@refresh.displayRefreshButton />
    <div onClick="Display(this)" id="bt_top_read" class="button buttonUp"></div>
    <div id="top_read" class="montre bd">
    <#if topread?string?trim=="nodata" || topread?string?trim=="error" || topread?string?trim=="invalid">
        <div class="${topread?string?trim}">${msg("${topread?string?trim}")}</div>
    <#else>
        ${topread}
    </#if>
    </div>
</div>

To get the Noderef in ftl file.

Define <param name="destination">{node.nodeRef}</param> in your action alfresco includes the noderef as a hidden input field.

Then youy can do document.getElementById("{}").value or YAHOO.util.Dom.get("{}").value to get the nodeRef.

Arjun
  • 624
  • 2
  • 6
  • Thank you for the reply. How is it related to the question? I*m pretty sure I didn't formulate my question very well. The question is: how to import an Alfresco [NodeRef](http://dev.alfresco.com/resource/AlfrescoOne/5.0/PublicAPI/org/alfresco/service/cmr/repository/NodeRef.html) (as example pointing to task-assignment.html.ftl) in the Freemarker template (as example shell.html.ftl)? – Kim Skovhus Andersen Apr 22 '21 at 08:55
  • I have updated my original answer and added the code snippets to get the noderef un ftl file. Hope this helps – Arjun Apr 22 '21 at 16:35
  • I'm testing in the JavaScript console. In the JavaScript input: var file = companyhome.childrenByXPath("/app:company"....etc); model['file'] = file[0].nodeRef; Then in the Freemarker input: <#import file as utils> 'Error reading imported template Node Type: {http://www.alfresco.org/model/content/1.0}content Node Ref: workspace://SpacesStore/34987sdf-9a8sdfa-asdfasdfasdf87 – Kim Skovhus Andersen Apr 23 '21 at 10:04