Default Fallback Value
ヘルパーは、属性が空または null の場合にデフォルトのフォールバック値を返すために使用されます。このメカニズムは、プロファイル属性とジャーニーイベントで機能します。
構文
Hello {%=profile.personalEmail.name.firstName ?: "there" %}!
この例では、このプロファイルの firstName
属性が空または null の場合、there
という値が表示されます。
if
ヘルパーを使用して、条件ブロックを定義します。
式の評価結果が true の場合、ブロックはレンダリングされます。true でない場合はスキップされます。
構文
{%#if contains(profile.personalEmail.address, ".edu")%}
<a href="https://www.adobe.com/academia">Check out this link</a>
if
ヘルパーの後に、else
ステートメントを入れて、その条件の結果が false の場合に実行するコードのブロックを指定することもできます。
elseif
ステートメントは、最初のステートメントが false を返した場合にテストする新しい条件を指定します。
形式
{
{
{%#if condition1%} element_1
{%else if condition2%} element_2
{%else%} default_element
{%/if%}
}
}
例
条件式に基づいて異なるストアのリンクをレンダリングする
{%#if profile.homeAddress.countryCode = "FR"%}
<a href="https://www.somedomain.com/fr">Consultez notre catalogue</a>
{%else%}
<a href="https://www.somedomain.com/en">Checkout our catalogue</a>
{%/if%}
メールアドレスの拡張子の判断
{%#if contains(profile.personalEmail.address, ".edu")%}
<a href="https://www.adobe.com/academia">Checkout our page for Academia personals</a>
{%else if contains(profile.personalEmail.address, ".org")%}
<a href="https://www.adobe.com/orgs">Checkout our page for Non Profits</a>
{%else%}
<a href="https://www.adobe.com/users">Checkout our page</a>
{%/if%}
条件付きリンクの追加
次の操作では、メールアドレスが「.edu」のプロファイルについては web サイト「www.adobe.com/academia」へのリンク、メールアドレスが「.org」のプロファイルについては「www.adobe.com/org」へのリンク、その他のすべてのプロファイルについてはデフォルトの URL「www.adobe.com/users」へのリンクを追加します。
{%#if contains(profile.personalEmail.address, ".edu")%}
<a href="https://www.adobe.com/academia">Checkout our page for Academia personals</a>
{%else if contains(profile.personalEmail.address, ".org")%}
<a href="https://www.adobe.com/orgs">Checkout our page for Non Profits</a>
{%else%}
<a href="https://www.adobe.com/users">Checkout our page</a>
{%/if%}
オーディエンスメンバーシップに基づく条件付きコンテンツ
{%#if profile.segmentMembership.get("ups").get("5fd513d7-d6cf-4ea2-856a-585150041a8b").status = "existing"%}
Hi! Esteemed gold member. <a href="https://www.somedomain.com/gold">Checkout your exclusive perks </a>
{%else%} if 'profile.segmentMembership.get("ups").get("5fd513d7-d6cf-4ea2-856a-585150041a8c").status = "existing"'%}
Hi! Esteemed silver member. <a href="https://www.somedomain.com/silver">Checkout your exclusive perks </a>
{%/if%}
オーディエンスとセグメント化サービスについて詳しくは、この節を参照してください。
unless
ヘルパーを使用して、条件ブロックを定義します。if
ヘルパーとは異なり、式の評価結果が false の場合にブロックがレンダリングされます。
構文
{%#unless unlessCondition%} element_1 {%else%} default_element {%/unless%}
例
メールアドレスの拡張子に基づいてコンテンツをレンダリングする。
{%#unless endsWith(profile.personalEmail.address, ".edu")%}
Some Normal Content
{%else%}
Some edu specific content Content
{%/unless%}
each
ヘルパーを使用して、配列に対して反復処理を行います。
ヘルパーの構文は {{#each ArrayName}}
YourContent {{/each}} です。
個々の配列項目は、ブロック内でキーワード this を使用して参照できます。配列の要素のインデックスは、{{@index}} を使用してレンダリングできます。
構文
{{#each profile.productsInCart}}
<li>{{this.name}}</li>
</br>
{{/each}}
例
{{#each profile.homeAddress.city}}
{{@index}} : {{this}}<br>
{{/each}}
例
ユーザーが買い物かごに入れた商品のリストをレンダリングする。
{{#each profile.products as |product|}}
<li>{{product.productName}} {{product.productRating}}</li>
</br>
{{/each}}
with
ヘルパーを使用して、template-part の評価トークンを変更します。
構文
{{#with profile.person.name}}
{{this.firstName}} {{this.lastName}}
{{/with}}
with
ヘルパーは、ショートカット変数を定義する場合にも使用できます。
例
with は、長い変数名に短い別名を付ける場合にも使用できます。
{{#with profile.person.name as |name|}}
Hi {{name.firstName}} {{name.lastName}}!
Checkout our trending products for today!
{{/with}}
let
関数を使用すると、式を変数として保存し、後からクエリで使用できます。
構文
{% let variable = expression %} {{variable}}
例
次の例では、合計が $100 以上 $1,000 未満のトランザクションで、すべての製品合計を米ドルで示します。
{% let variable = expression %} {{variable}}