Template
Core library Template — HTML templates for messages (init, add, retrieve, update, remove).
Template manages template definitions (TemplateName, LayoutHTML, customer key, etc.). Use Retrieve with optional QueryAllAccounts: true to search across accessible accounts.
Requires Platform.Load("core", "1.1.5") before use.
Methods
| Method | Returns | Description |
|---|---|---|
Template.Init(key) |
TemplateInstance | Bind by external key |
Template.Add(properties) |
string | Create a template |
Template.Retrieve(filter) |
object[] | Query templates |
<TemplateInstance>.Update(properties) |
string | Update the initialized template |
Template.Init
Initializes a Template instance for the given external key.
Syntax
Template.Init(key)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
key |
string | Yes | External key |
Return value
TemplateInstance
Examples
Platform.Load("core", "1");
var t = Template.Init("myTemplate");
Template.Add
Creates a new template with the specified properties.
Syntax
Template.Add(properties)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
properties |
object | Yes | CustomerKey, TemplateName, LayoutHTML, … |
Return value
"OK" on success.
Examples
Platform.Load("core", "1");
var myTemp = {
CustomerKey: "test_template",
TemplateName: "SSJS Test Template",
LayoutHTML: "this is some HTML"
};
var status = Template.Add(myTemp);
Template.Retrieve
Queries templates matching the given filter. Pass { Filter: { Property, SimpleOperator, Value }, QueryAllAccounts: true } to search all accessible accounts.
Syntax
Template.Retrieve(filter)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
filter |
object | Yes | WSProxy-style filter (optionally with QueryAllAccounts) |
Return value
object[]
Examples
Platform.Load("core", "1.1.5");
var getTemplate = Template.Retrieve({
Property: "CustomerKey",
SimpleOperator: "equals",
Value: "MyTemplate"
});
<TemplateInstance>.Update
Updates the initialized template with the given properties.
Syntax
<TemplateInstance>.Update(properties)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
properties |
object | Yes | Attributes to change |
Return value
"OK" on success.
Examples
Platform.Load("core", "1.1.5");
var myTemplate = Template.Init("myTemplateCK");
var status = myTemplate.Update({ TemplateName: "Edited Template" });