メルリンAIジンジャーアシスタントのインスピレーションライブラリ

この記事では、自然言語クエリからJinjaコードを生成するためのベストプラクティスの例を紹介し、動的コンテンツの実装を簡素化します。あなたの自然言語クエリの詳細に直接対応するJinjaコードが生成されることを理解することが重要です。最適な結果を得るには、自然言語のクエリが構造化され、正確な属性名と、希望する動的コンテンツに関する関連情報が含まれていることを確認してください。

❌ 悪いJinjaの説明:

類似アイテムからのタイトルと説明。説明が50文字を超える場合は、説明を切り詰めてください。

✅ 良いJinjaの説明:

製品セット Similar_Items のタイトルと説明を6つ表示します。50文字以上の説明を切り捨てます。

インスピレーションライブラリ

Merlin AI Jinja アシスタントを使用すると、簡単に動的コンテンツを作成できます。以下は、自然言語クエリのいくつかの例と、それに対応するJinjaコード出力です。これらの例は、最適なJinjaコード生成のために、自分自身の詳細な自然言語リクエストを作成するためのインスピレーションを提供できます。

ダイナミックコンテンツ カスタムソリューション
配列データ型のイベント属性「Product Titles」からすべての値を印刷します。
Jinja
{% for title in EventAttribute['Product Titles'] %} {{ title }} {% endfor %}
イベント属性["Product Titles"]の配列データ型の最初の値が'Tシャツ'である場合のみ、それを印刷します。
Jinja
{% if EventAttribute['Product Titles'][0] == 'Tshirt' %}{{ EventAttribute['Product Titles'][0] }}{% endif %}

商品セット.クーポンコードのオブジェクトデータ型から最初の10個の製品タイトルを印刷します。製品セットに十分な製品がない場合は、製品セットを使用してください。デモおすすめの製品を追加して、両方の製品セットからのタイトルの完全なリストが10になるようにします。
Jinja
{% set products = ProductSet.CouponCode[:10] %}
{% if products|length < 10 %}
{% set additional_products = ProductSet.DemoRecommendations[:10 - products|length] %}
{% set products = products + additional_products %}
{% endif %}
{% for product in products %}
{{ product.title }}
{% endfor %}

製品セットのデモ推奨事項を取得します。存在するか確認し、存在する場合は、製品セットからタイトルを最大5件印刷しますが、20文字に切り捨てます。

Jinja
{% if ProductSet.DemoRecommendations %}
    {% for product in ProductSet.DemoRecommendations[:5] %}
        {{ product.title[:20] + '...' if product.title|length  20 else product.title }}
    {% endfor %}
{% endif %}

製品セットデモ推奨事項 から存在を確認し、製品セットデモ推奨事項 の 製品タイトル と 製品価格 を取得しますが、奇数のみを取得し、シリアル番号も追加します。
Jinja
{% if ProductSet.DemoRecommendations %}
    {% for product in ProductSet.DemoRecommendations %}
        {% if loop.index is odd %}
            {{ loop.index }}. {{ product.title }} - {{ product.price }}
        {% endif %}
    {% endfor %}
{% endif %}

製品セットのクーポンコードが存在するか確認し、製品セットのクーポンコードに対して、割引価格が50%であるべき製品の価格を取得します。
Jinja
{% if ProductSet.CouponCode %}  
{% for product in ProductSet.CouponCode %}  
{{ product.price * 0.5 }}  
{% endfor %}  
{% endif %}

製品セットのクーポンコード が存在する場合は、製品セットのクーポンコード を取得します。製品タイトルの数が6であることを確認し、6つの製品タイトルを取得します。製品の数が6未満の場合は、他の製品セットデモ推奨事項を実行し、この製品セットデモ推奨事項から残りの製品を取得します。両方の製品セットに同じ製品がある場合は、1つの製品のみを表示します。
Jinja
{% set displayed_titles = [] %}
{% if ProductSet.CouponCode %}
{% for product in ProductSet.CouponCode %}
{% if displayed_titles|length < 6 and product.title not in displayed_titles %}
{{ product.title }}
{% set _ = displayed_titles.append(product.title) %}
{% endif %}
{% endfor %}
{% endif %}
{% if displayed_titles|length < 6 and ProductSet.DemoRecommendations %}
{% for product in ProductSet.DemoRecommendations %}
{% if displayed_titles|length < 6 and product.title not in displayed_titles %}
{{ product.title }}
{% set _ = displayed_titles.append(product.title) %}
{% endif %}
{% endfor %}
{% endif %}

製品セットデモ推奨事項を使用して、どのようなパーソナライズを行うことができますか?私は一つの製品だけが欲しいです。価格も追加できますか?
Jinja
{% if ProductSet.DemoRecommendations %}
  {% for product in ProductSet.DemoRecommendations[0:1] %}
    {{ product.title }} - {{ product.price }}
  {% endfor %}
{% endif %}

Jinjaコードを作成して、ユーザー属性データ型の値が文字列か文字列の配列かをチェックする条件を作成してください。
Jinja
{% if UserAttribute is string %}
  
{% elif UserAttribute is sequence and UserAttribute[0] is string %}
  
{% endif %}

この JINJA を修正してください {% if ProductSet.DemoRecommendations %} {% for product in ProductSet.DemoRecommendations[:5] %} {{ product.[:20] + '...' if product.title|length > 20 else product.title }} {% endfor %} {% endif %}
Jinja
{% if ProductSet.DemoRecommendations %}
{% for product in ProductSet.DemoRecommendations[:5] %}
{{ product.title[:19] + '...' if product.title|length > 20 else product.title }}
{% endfor %}
{% endif %}

現在の時間をHH:MM:SS形式で取得するにはどうすればよいですか?

Jinja
{{ '%H:%M:%S' | today() }}

イベント属性の配信日を抽出し、dd/mm/yyyy形式にフォーマットし、今日の日付との日数の差をISTタイムゾーンで計算し、差が2日以上か2日未満かを確認する条件チェックを処理するプログラムが必要です。日付を覚えておいてください。配達日付は未来または過去のものである可能性がありますが、絶対的な差を考慮する必要があります。

Jinja
{% set date = EventAttribute['Delivery Date'] %}
{% set now = '%d/%m/%Y'|today('IST') %}
{% set diff = (EventAttribute['Delivery Date']|dateFormatter('%d/%m/%Y')|days('%d/%m/%Y'|today('IST')))|abs %}
{% if diff = 2 %}
    {{ "Difference is greater than or equal to 2 days." }}
{% else %}
    {{ "Difference is less than 2 days." }}
{% endif %}

2つの日付の違いを表示する日付時刻フォーマッターが欲しいです。

Jinja
{% set date1 = UserAttribute['Date1'] %}
{% set date2 = UserAttribute['Date2'] %}
{% set diff = date1|dateFormatter('%d/%m/%Y')|days(date2|dateFormatter('%d/%m/%Y')) %}
{% set year = diff // 365 %}
{% set month = (diff - (year * 365)) // 30 %}
{% set day = diff - (year * 365) - (month * 30) %}
{{ year }} 年, {{ month }} ヶ月, {{ day }} 日

クーポンコードの製品セットからタイトルを取得します。重複する説明がある場合は、最初の値のみを保持して削除してください。最後に、ユニークなタイトルと説明のみを印刷します。

Jinja
{% set unique_titles = [] %}
{% set unique_descriptions = [] %}
{% if ProductSet.CouponCode %}
    {% for product in ProductSet.CouponCode %}
        {% if product.description not in unique_descriptions %}
            {{ unique_titles.append(product.title)|replace('None', '') }}
            {{ unique_descriptions.append(product.description)|replace('None', '') }}
        {% endif %}
    {% endfor %}
{% endif %}
{% for i in range(0, unique_titles|length) %}
    {{ unique_titles[i] }}: {{ unique_descriptions[i] }}
{% endfor %}

名前を印刷してください。

Jinja
{{ UserAttribute['First Name'] }}

次のSMSに対して、イベント属性「通貨」と「注文金額」をJinjaでサポートする必要があります。こんにちは。あなたの支払い({{Order Value}})は、クレジットカードが現在停止されているため拒否されました。ルール 1. 主な通貨は、次のように記号でフォーマットする必要があります: GBP = £、USD = $、AUD = $、EUR = €(重要: 通貨記号と「金額」の間にスペースを入れないこと。例: €8.00)。ペイロードに来る可能性のある他の通貨コードは、その通貨コードを維持します。例: AED 8.00(重要: 通貨記号と「注文金額」の間にスペース)2. 「注文金額」は1000の区切りでフォーマットする必要があります。例えば、1,989、12,986、123,098など。

Jinja
{% set currency_symbols = {'GBP': '£', 'USD': '$', 'AUD': '$', 'EUR': '€'} %}
{% set currency_symbol = currency_symbols.get(currency, currency) %}
{% if currency in currency_symbols %}
    {% set formatted_amount = amount|string|replace(',', '')|int|format('%0,.2f') %}
    {% set display_amount = currency_symbol ~ formatted_amount %}
{% else %}
    {% set formatted_amount = amount|string|replace(',', '')|int|format('%0,.2f') %}
    {% set display_amount = currency_symbol ~ ' ' ~ formatted_amount %}
{% endif %}
こんにちは。あなたの{{ Order Value }}の支払いは拒否されました。クレジットカードが現在停止中です。お送りしたメールをご確認いただくか、助けが必要な場合はご連絡ください。

イベント属性「Product Titles」の最初と二番目の値を、'+'で連結します。結合された値が5文字を超える場合は、結合された文字列の5文字を印刷し、その後に「...」を追加します。
ジンジャ
{% set concatenated = EventAttribute['Product Titles'][0] ~ '+' ~ EventAttribute['Product Titles'][1] %}
{% if concatenated|length  5 %}
    {{ concatenated[:5] ~ '...' }}
{% else %}
    {{ concatenated }}
{% endif %}

"Fix this Jinja"

{% set target_date = '13/03/2025' %}
{% set today_date = '%d/%m/%Y'|today('EST') %}
{% set diff = target|days(today_date) %}
{{ diff }} 日

Jinja
{% set target_date = '13/03/2025' %}
{% set today_date = '%d/%m/%Y'|today('EST') %}
{% set diff = target_date|days(today_date) %}
{{ diff }} Days

イベント属性「注文の値」の末尾の小数点以下のゼロを削除し、データ型をフロートから弦 に変換します。
Jinja
{% set value = EventAttribute['Order Value'] %} {% set formatted_value = ('%.15g' % value)|string %} {{ formatted_value }}

この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています

How can we improve this article?