장바구니 상품, 주문 항목 또는 추천과 같은 여러 항목을 사용하기 위해 객체 배열을 전달합니다. 배열은 직접 접근(인덱싱)과 반복(루프)을 모두 지원합니다.사용 사례: 상품 목록, 리더보드, 주문 요약 또는 다중 항목 데이터를 표시하는 경우.인덱싱 템플릿 (첫 번째 항목 접근):
Liquid
Your {{message.custom_data.cart_items[0].item_name}} is waiting for you!Image: {{message.custom_data.cart_items[0].img_url}}
배열 인덱싱은 0부터 시작합니다, 1이 아닙니다. 첫 번째 항목은 [0], 두 번째는 [1] 등입니다. 존재하지 않는 인덱스에 접근하면 빈 값이 반환됩니다 (오류가 발생하지 않음).
루프 템플릿 (모든 항목 접근):
Liquid
{% for item in message.custom_data.cart_items %}- {{ item.item_name }} — {{ item.img_url }}{% endfor %}
단일 API 요청으로 여러 사용자에게 메시지를 전송하며, 각 수신자는 자신의 external_id를 기반으로 개인화된 콘텐츠를 확인합니다.작동 방식:
custom_data를 키가 external_id이고 값이 사용자별 데이터인 객체로 구성합니다
템플릿에서 subscription.external_id를 사용하여 현재 수신자의 데이터를 조회합니다
OneSignal은 각 수신자의 특정 데이터로 수신자당 한 번 템플릿을 렌더링합니다
템플릿:
{% assign user = message.custom_data.users[subscription.external_id] %}Hi {{ user.first_name }}, you have {{ user.points }} points. Your level is {{ user.level }}.
동작 설명:
subscription.external_id에는 현재 수신자의 external_id가 포함됩니다 (예: “user123”)
message.custom_data.users[subscription.external_id]는 custom_data 객체에서 해당 사용자의 데이터를 조회합니다
Messages > Templates > New Email Template로 이동하여 드래그 앤 드롭 편집기를 엽니다.
2
레이아웃 구조 추가
5개의 행을 생성합니다:
행 1, 2, 4: Paragraph 블록이 있는 단일 열
행 3: HTML | Paragraph | Paragraph | Paragraph의 4열
행 5: Button 블록이 있는 단일 열
장바구니 이탈용 기본 이메일 템플릿
3
항목 수 표시
행 1에 다음을 추가합니다:
Liquid
We're holding onto {{message.custom_data.cart.size}} items in your cart, but don't wait too long, other squirrels are getting ahead!
더 나은 문법을 위해 “1 item”과 “2 items”를 구분하는 조건문을 사용할 수 있지만, 장바구니 이탈 이메일에서는 보통 복수형이 허용됩니다.
Liquid
{% assign cart = message.custom_data.cart %}{% assign item_count = cart.size | plus: 0 %}{% if item_count == 1 %}We're holding onto {{item_count}} item in your cart, but don't wait too long, other squirrels are getting ahead!{% endif %}{% if item_count > 1 %}We're holding onto {{item_count}} items in your cart, but don't wait too long, other squirrels are getting ahead!{% endif %}
4
루프 시작
for 루프를 사용하여 장바구니의 각 항목에 대해 상품 표시 행을 반복합니다.행 2(루프 시작)의 텍스트 블록에 다음을 추가합니다:
Text
{% for product in message.custom_data.cart %}
동작 설명:
cart 배열의 각 객체를 반복하는 루프를 시작합니다
현재 항목을 나타내는 product라는 임시 변수를 생성합니다
{% for %}와 {% endfor %} 사이의 모든 내용이 장바구니 항목당 한 번 반복됩니다
product 대신 아무 이름이나 사용할 수 있습니다 (예: item, cartItem) — 일관되게만 유지하세요
For 루프 배치: {% for %} 구문이 자체 텍스트 블록 행에 있는지 확인하세요. 다른 콘텐츠가 있는 다중 열 행 안에 넣지 마세요. 일부 이메일 클라이언트에서 렌더링이 깨질 수 있습니다.
5
상품 세부 정보 표시
이 4열 행은 이미지, 이름, 수량, 가격을 표시합니다. 루프 내부에 있으므로 모든 장바구니 항목에 대해 반복됩니다.행 3(상품 세부 정보)에서 구성합니다:열 1 - HTML 블록 (상품 이미지):
푸시 알림은 문자 수 제한과 운영체제 제한이 있으므로, 모든 항목을 표시하는 대신 첫 번째 상품을 표시하고 적절한 문법으로 총 수를 나타냅니다.다음은 구축할 푸시 알림 예시입니다:
장바구니 이탈 푸시 템플릿 예시
메시지 필드:
Liquid
{% assign cart = message.custom_data.cart %}{% assign item_count = cart.size | plus: 0 %}{% if item_count == 1 %}You left {{cart.first.product_name}} in your cart.{% endif %}{% if item_count == 2 %}You left {{cart.first.product_name}} and {{item_count | minus: 1}} more item in your cart.{% endif %}{% if item_count > 2 %}You left {{cart.first.product_name}} and {{item_count | minus: 1}} more items in your cart.{% endif %}