テンプレートを作成する
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
POST /v3/templates
テンプレートを作成します。
少なくとも、要求本文で次の必須属性を指定する必要があります。
|
属性 |
種類 |
形容 |
使用例 |
|---|---|---|---|
|
name |
糸 |
テンプレートの名前。 |
"Alert bar template" |
|
friendlyId |
糸 |
テンプレートの一意のID。 小文字の英数字とアンダースコアのみを使用できます。 |
"alert_bar_template_1" |
|
type |
string enum (大文字) |
テンプレートのタイプ。 |
次のいずれかである必要があります。
|
|
status |
string enum (大文字) |
テンプレートの現在のステータス。 |
次のいずれかである必要があります。
|
|
description |
糸 |
接続の説明。 |
"Alert bar web template" |
|
render |
ブーリアン |
WebテンプレートのプレビューをSitecore Personalizeアプリでレンダリングするかどうかを決定します。 これをtrueに設定するのは、Webテンプレートがレンダリングできると確信している場合にのみ行ってください。 ハンドルバーループを使用するより高度なWebテンプレートでは、これをtrueに設定しないでください。 |
true, false |
|
defaultTemplate |
ブーリアン |
これがデフォルトのテンプレートであるかどうかを判断します。 テンプレートを作成するときは、この値をfalseに設定する必要があります。 |
false |
|
customTemplate |
ブーリアン |
これがカスタムテンプレートであるかどうかを判断します。 テンプレートを作成するときは、この値をtrueに設定する必要があります。 |
true |
|
templateElements 随意 |
JSONオブジェクトのJSON配列 |
テンプレートを定義するカスタムHTML、CSS、JavaScript、FreeMarkerコード。 |
該当なし |
オプションのtemplateElements配列オブジェクトを使用すると、HTML、CSS、JavaScript、およびFreeMarkerコードをテンプレートに含めることができます。 templateElementsのオブジェクトには、次の属性を使用します。
|
属性 |
種類 |
形容 |
使用例 |
|---|---|---|---|
|
id |
string enum (小文字) |
template属性に含めるコードの種類。 例えば、テンプレートにCSSコードを含めるには、この値を "css"に設定し、template属性でカスタムCSSコードを指定します。 |
次のいずれかである必要があります。
|
|
template |
糸 |
文字列化されたHTML、CSS、JavaScript、またはFreeMarkerコード。 FreeMarkerコードの場合は、少なくとも 開始中括弧と終了中括弧 {}を含める必要があります。 |
|
次に、オブジェクトのtemplateElements配列の例を示します。
"templateElements": [ { "id": "html", "template": "<div id=\"test\">My test div</div>" }, { "id": "css", "template": "#test {text-transform: uppercase}" }, { "id": "js", "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")" }, { "id": "freemarker", "template": "{}" } ]
応答では、refキーにテンプレート参照が含まれています。
テンプレート参照は、特定のテンプレートと対話するために使用します (たとえば、テンプレート を取得 または 更新 するなど)。
curl -X POST '<baseURL>/v3/templates' \ -H 'Authorization: Bearer <accessToken>' \ -H 'Accept: application/json' \ --data-raw ' { "name": "Alert bar template", "friendlyId": "alert_bar_template_1", "type": "WEB", "status": "DRAFT", "description": "Alert bar template WEB", "render": false, "defaultTemplate": false, "customTemplate": true, "templateElements": [ { "id": "html", "template": "<div id=\"test\">My test div</div>" }, { "id": "css", "template": "#test {text-transform: uppercase}" }, { "id": "js", "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")" }, { "id": "freemarker", "template": "{}" } ] }'
{ "clientKey": "pqsPERS3lw12v5a9rrHPW1c4hET73GxQ", "href": "<baseURL>/v3/templates/340ced1b-c9b7-43f0-9eec-2b9f0b7693fa", "ref": "340ced1b-c9b7-43f0-9eec-2b9f0b7693fa", "name": "Alert bar template", "description": "Alert bar template WEB", "modifiedByRef": "zwxCA58jwLzfeU2mNGgalCpoJzNVYOJl@clients", "modifiedAt": "2025-07-12T10:56:46.53994Z", "revision": 1, "archived": false, "friendlyId": "alert_bar_template_1", "type": "WEB", "status": "DRAFT", "templateElements": [ { "id": "html", "template": "<div id=\"test\">My test div</div>" }, { "id": "css", "template": "#test {text-transform: uppercase}" }, { "id": "js", "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")" }, { "id": "freemarker", "template": "{}" } ], "render": false, "defaultTemplate": false, "tags": [], "customTemplate": true }