ヘルパー gs-helpers

デフォルトのフォールバック値 default-value

Default Fallback Value ヘルパーは、属性が空または null の場合にデフォルトのフォールバック値を返すために使用されます。このメカニズムは、プロファイル属性とジャーニーイベントで機能します。

構文

Hello {%=profile.personalEmail.name.firstName ?: "there" %}!

この例では、このプロファイルの firstName 属性が空または null の場合、there という値が表示されます。

条件 if-function

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%}
    }
}

  1. 条件式に基づいて異なるストアのリンクをレンダリングする

    code language-sql
    {%#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%}
    
  2. メールアドレスの拡張子の判断

    code language-sql
    {%#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%}
    
  3. 条件付きリンクの追加

    次の操作では、メールアドレスが「.edu」のプロファイルについては web サイト「www.adobe.com/academia」へのリンク、メールアドレスが「.org」のプロファイルについては「www.adobe.com/org」へのリンク、その他のすべてのプロファイルについてはデフォルトの URL「www.adobe.com/users」へのリンクを追加します。

    code language-sql
    {%#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%}
    
  4. オーディエンスメンバーシップに基づく条件付きコンテンツ

    code language-sql
    {%#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%}
    
NOTE
オーディエンスとセグメント化サービスについて詳しくは、この節を参照してください。

Unless unless

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

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 with

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

let 関数を使用すると、式を変数として保存し、後からクエリで使用できます。

構文

{% let variable = expression %} {{variable}}

次の例では、買い物かご内の価格が 100 ~ 1000 の商品の合計価格を計算できます。

{% let sum = 0%}
    {{#each profile.productsInCart as |p|}}
        {%#if p.price>100 and p.price<1000%}
            {%let sum = sum + p.price %}
        {%/if%}
    {{/each}}
{{sum}}
recommendation-more-help
b22c9c5d-9208-48f4-b874-1cefb8df4d76