Liquid Snippets by ALSEL
UI部品初級

ニュースレター登録フォーム

メールアドレス入力欄と送信ボタンを備えたニュースレター購読セクション。背景色・ボーダー・余白をテーマカスタマイザーで自由にカスタマイズでき、送信後に確認メッセージを表示する。

用途
ストアのホームページやフッター領域に配置して、訪問者のメールアドレスを「ニュースレター」タグ付きで顧客リストに登録する。セールやキャンペーン情報を配信するための購読者獲得に用いる。
設置場所
sections/newsletter.liquid に配置し、ホームページテンプレート(index.liquid)やフッターセクション内で `{% section 'newsletter' %}` で読み込む。テーマカスタマイザーから背景色・ボタンスタイル・タイトルテキストを管理できる。
注意点
メールフォームの送信には Shopify のカスタマー管理 API が自動で連携するため、別途バックエンド設定は不要。ただし「ニュースレター」タグが既存顧客に付与されるため、管理画面で顧客タグの命名ルールを統一しておく。section-header スニペットが別途必要で、title・description・font-size の表示に依存するため事前に確認する。メールバリデーションはブラウザの type="email" で行われるが、サーバー側の検証も Shopify が自動処理する。
タグ:newsletterformemailsubscribesection

コード

280 行 / liquid
<div
  id="newsletter-{{ section.id }}" 
  class="
    newsletter 
    {{ section.settings.bg_color }} 
    {{ section.settings.bg_gradient }}
    {{ section.settings.text_color }}
    {{ section.settings.border_top_width | prepend: 'border-top-' }}
    {{ section.settings.border_bottom_width | prepend: 'border-bottom-' }}
    {{ section.settings.border_color }} 
    {{ section.settings.pt | prepend: 'pt-' }} 
    {{ section.settings.pb | prepend: 'pb-' }}
  "
  style="
    --bs-bg-opacity: {{ section.settings.bg_opacity | append: '%' }};
    --bs-border-opacity: {{ section.settings.border_opacity | append: '%' }};
  ">
  <div 
    class="container"
    style="max-width: {{ section.settings.container_max_width }}px;">
    {% render 'section-header' %}
    {% form 'customer', class: 'newsletter-form' %}
      <input type="hidden" name="contact[tags]" value="newsletter">
      {{ form.errors | default_errors }}
      {% if form.posted_successfully? %}
        <p class="alert alert-success">
          {{ 'general.newsletter.confirmation_text' | t }}
        </p>
      {% endif %}
      <div class="form-floating mt-n3">
        <div class="form-floating-icon">
          {% render 'svg-icons', icon: 'mail' %}
        </div>
        <input 
          id="newsletter-input-email"
          type="email" 
          name="contact[email]" 
          size="30"
          class="form-control" 
          value="{% if customer.email != blank %}{{ customer.email }}{% endif %}" 
          placeholder="{{ 'general.newsletter.input_label' | t }}"
          autocorrect="off" 
          autocapitalize="off">
        <label for="newsletter-input-email">
          {{ 'general.newsletter.input_label' | t }}
        </label>
        <button 
          class="btn {{ section.settings.btn_color }} {{ section.settings.btn_size }}" 
          type="submit" 
          name="commit"
          aria-label="{{ 'general.newsletter.submit_button' | t }}">
          <svg width="22" height="22" viewBox="0 0 512 512" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                <path d="M28,61 C28,161.710136 28,212.065204 28,212.065204 C28,212.065204 351.044692,255.885938 351.044692,255.885938 C351.044692,255.885938 243.363128,270.4319 28,299.523824 L28,451 L483.555218,256 L28,61 Z" fill="currentColor"></path>
            </g>
          </svg>
        </button>
      </div>
      {% unless section.settings.notice == blank %}
        <div class="newsletter-notice rte mt-4 lh-sm small text-center opacity-70 fst-italic">
          {{ section.settings.notice }}
        </div>
      {% endunless %}
    {% endform %}
  </div>
</div>

{% schema %}
{
  "name": "Newsletter",
  "tag": "section",
  "settings": [
    {
      "type": "header",
      "content": "Styling"
    },
    {
      "type": "select",
      "id": "bg_color",
      "label": "Background color",
      "default": "bg-body",
      "options": [
        { "value": "bg-primary", "label": "Primary" },
        { "value": "bg-secondary", "label": "Secondary" },
        { "value": "bg-body", "label": "Body" },
        { "value": "bg-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "bg_opacity",
      "label": "Background opacity",
      "min": 0,
      "max": 100,
      "step": 1,
      "default": 100,
      "unit": "%"
    },
    {
      "type": "select",
      "id": "bg_gradient",
      "label": "Background gradient",
      "options": [
        { "value": "bg-gradient", "label": "Yes" },
        { "value": "", "label": "No" }
      ],
      "default": ""
    },
    {
      "type": "select",
      "id": "text_color",
      "label": "Text color",
      "default": "text-body",
      "options": [
        { "value": "text-primary", "label": "Primary" },
        { "value": "text-secondary", "label": "Secondary" },
        { "value": "text-body", "label": "Body" },
        { "value": "text-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "border_top_width",
      "label": "Border top width",
      "default": 0,
      "min": 0,
      "max": 16,
      "step": 1,
      "unit": "px"
    },
    {
      "type": "range",
      "id": "border_bottom_width",
      "label": "Border bottom width",
      "default": 0,
      "min": 0,
      "max": 16,
      "step": 1,
      "unit": "px"
    },
    {
      "type": "select",
      "id": "border_color",
      "label": "Border color",
      "default": "border-body",
      "options": [
        { "value": "border-primary", "label": "Primary" },
        { "value": "border-secondary", "label": "Secondary" },
        { "value": "border-body", "label": "Body" },
        { "value": "border-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "border_opacity",
      "label": "Border opacity",
      "min": 0,
      "max": 100,
      "step": 1,
      "default": 100,
      "unit": "%"
    },
    {
      "type": "text",
      "id": "container_max_width",
      "label": "Container max-width (px)",
      "info": "Leave empty to use the global container width"
    },
    {
      "type": "header",
      "content": "Header"
    },

    {
      "type": "text",
      "id": "header_title",
      "label": "Title",
      "default": "Newsletter Subscribe"
    },
    {
      "type": "select",
      "id": "header_title_font_size",
      "label": "Title font-size",
      "default": "h2",
      "options": [
        { "value": "h1", "label": "H1" },
        { "value": "h2", "label": "H2" },
        { "value": "h3", "label": "H3" },
        { "value": "h4", "label": "H4" },
        { "value": "h5", "label": "H5" },
        { "value": "h6", "label": "H6" }
      ]
    },
    {
      "type": "richtext",
      "id": "header_description",
      "label": "Description (optional)",
      "default": "<p>Add on optional description for this section</p>"
    },
    {
      "type": "select",
      "id": "header_description_font_size",
      "label": "Description font-size",
      "default": "fs-md",
      "options": [
        { "value": "fs-sm", "label": "sm" },
        { "value": "fs-md", "label": "md" },
        { "value": "fs-lg", "label": "lg" },
        { "value": "fs-xl", "label": "xl" },
        { "value": "fs-xxl", "label": "xxl" }
      ]
    },
    {
      "type": "header",
      "content": "Newsletter form"
    },
    {
      "type": "select",
      "id": "btn_color",
      "label": "Button color",
      "default": "btn-primary",
      "options": [
        { "group": "Solid", "value": "btn-primary", "label": "Primary" },
        { "group": "Solid", "value": "btn-secondary", "label": "Secondary" },
        { "group": "Solid", "value": "btn-white", "label": "White" },
        { "group": "Light", "value": "btn-light-primary", "label": "Primary" },
        { "group": "Light", "value": "btn-light-secondary", "label": "Secondary" },
        { "group": "Light", "value": "btn-light-white", "label": "White" },
        { "group": "Outline", "value": "btn-outline-primary", "label": "Primary" },
        { "group": "Outline", "value": "btn-outline-secondary", "label": "Secondary" },
        { "group": "Outline", "value": "btn-outline-white", "label": "White" }
      ]
    },
    {
      "type": "select",
      "id": "btn_size",
      "label": "Button size",
      "default": "",
      "options": [
        { "value": "btn-sm", "label": "Small" },
        { "value": "", "label": "Medium" },
        { "value": "btn-lg", "label": "Large" }
      ]
    },
    {
      "type": "richtext",
      "id": "notice",
      "label": "Notice text",
      "default": "<p>By signing up for email, you agree to our <a href=\"/policies/terms-of-service\">Terms of Service</a> and <a href=\"/policies/privacy-policy\">Privacy Policy</a>.</p>"
    },
    {
      "type": "header",
      "content": "Spacing"
    },
    {
      "type": "range",
      "id": "pt",
      "label": "Top",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 10
    },
    {
      "type": "range",
      "id": "pb",
      "label": "Bottom",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 10
    }
  ],
  "presets": [
    {
      "name": "Newsletter"
    }
  ]
}
{% endschema %}

出典・ライセンス

License:
MIT

このコードは kondasoft 著作の MIT ライセンスソースです。 原本の著作権は kondasoft が保有します。日本語訳は ALSEL によるものです。

関連項目

UI部品初級

成功チェックマークアイコン

緑色の円形背景にチェックマークを描いたSVGアイコン。フォームやメッセージの完了状態を視覚的に表現する。

📁 shopify-headless-theme·MIT·6
UI部品初級

エラーアイコン

エラー状態を示す円形アイコン。SVG で描画されたアラート記号を含む UI 部品で、accessibility 対応により視覚障害ユーザーには非表示。

📁 theme-tools·MIT·8
UI部品中級

カスタム要素のラッパーコンポーネント

child-element というカスタム HTML 要素をラップし、スロットに子要素を挿入するスニペット。Web Components パターンで再利用可能なコンポーネント構造を実現する。

📁 theme-tools·MIT·10
UI部品初級

静的コンテンツ

管理画面で入力したテキストコンテンツを静的に描画するブロック。セクション内で複数回使い分けられる汎用コンテナとして機能する。

📁 theme-tools·MIT·11
UI部品初級

テキスト

セクションに追加できるシンプルなテキストブロック。管理画面からドラッグ&ドロップで配置でき、固定テキスト「hello world」を表示する基本的なブロック実装。

📁 theme-tools·MIT·15
UI部品初級

セクション共通ヘッダー(タイトル・説明文)

セクション内で繰り返し使うタイトルと説明文をまとめて描画するスニペット。テーマカスタマイザーから設定したテキストとフォントサイズを条件付きで出力する。

📁 ks-bootshop·MIT·24