0
# Template Engine & Rendering
1
2
Template processing system supporting FreeMarker, Velocity, and custom template languages for form and content rendering.
3
4
## Capabilities
5
6
### Template Management
7
8
```java { .api }
9
interface DDMTemplateManager {
10
Map<String, Object> getAutocompleteVariables(
11
HttpServletRequest httpServletRequest,
12
HttpServletResponse httpServletResponse,
13
Language language) throws Exception;
14
15
String[] getRestrictedVariables(Language language);
16
17
boolean isAutocompleteEnabled(Language language);
18
}
19
20
enum Language {
21
FREEMARKER("ftl"),
22
VELOCITY("vm"),
23
JAVASCRIPT("js");
24
25
String getExtension();
26
}
27
```
28
29
### Template Rendering
30
31
```java { .api }
32
interface DDMDisplay {
33
String getEditTemplateBackURL(HttpServletRequest httpServletRequest,
34
DDMTemplate template) throws PortalException;
35
36
String getViewTemplateBackURL(HttpServletRequest httpServletRequest,
37
DDMTemplate template) throws PortalException;
38
39
boolean isShowConfirmSelectStructure();
40
boolean isShowConfirmSelectTemplate();
41
}
42
```
43
44
## Usage Examples
45
46
### Creating and Using Templates
47
48
```java
49
@Component
50
public class TemplateExample {
51
52
@Reference
53
private DDMTemplateLocalService templateLocalService;
54
55
public DDMTemplate createDisplayTemplate(long groupId, long structureId, long userId)
56
throws PortalException {
57
58
String script =
59
"<#list entries as entry>" +
60
" <div class=\"entry\">" +
61
" <h3>${entry.title}</h3>" +
62
" <p>${entry.description}</p>" +
63
" </div>" +
64
"</#list>";
65
66
Map<Locale, String> nameMap = Collections.singletonMap(Locale.US, "Entry Display Template");
67
Map<Locale, String> descriptionMap = Collections.singletonMap(Locale.US, "Template for displaying entries");
68
69
ServiceContext serviceContext = new ServiceContext();
70
serviceContext.setScopeGroupId(groupId);
71
72
return templateLocalService.addTemplate(
73
userId, groupId,
74
PortalUtil.getClassNameId(DDMStructure.class), structureId,
75
PortalUtil.getClassNameId(DDMTemplate.class),
76
null, // auto-generate template key
77
nameMap, descriptionMap,
78
DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY,
79
DDMTemplateConstants.TEMPLATE_MODE_CREATE,
80
Language.FREEMARKER.getValue(),
81
script, true, // cacheable
82
false, null, null, // no small image
83
serviceContext
84
);
85
}
86
}
87
```