> ## Documentation Index
> Fetch the complete documentation index at: https://developers.hubspot.jp/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# モジュールとテーマのフィールドの概要

> HubSpotのモジュールとテーマは、制作担当者がフィールドを使用してカスタマイズできます。開発者はfields.jsonファイルを駆使してフィールドの作成と整理を行います。

[モジュール](https://developers.hubspot.jp/docs/cms/start-building/building-blocks/modules/overview)と[テーマ](/cms/start-building/building-blocks/overview)内では、フィールドを使用して、制作担当者がモジュールとテーマのスタイルや機能をウェブサイト上で制御できます。モジュールまたはテーマを開発する場合は、`fields.json`ファイルにフィールドを組み込み、テーマエディターとコンテンツエディターに変換します。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023/theme-settings-fields.png" alt="テーマ設定モジュール" />
</Frame>

この記事では、モジュールとテーマのフィールドのオプションを、作成および管理する方法を詳しく説明します。特定のフィールドタイプの詳細については、[モジュールとテーマのフィールドに関するリファレンスガイド](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields)をご覧ください。

## フィールドの作成と管理

[モジュール](https://developers.hubspot.jp/docs/cms/start-building/building-blocks/modules/overview)の`fields.json`ファイルには、[HubSpot CLI](/developer-tooling/local-development/hubspot-cli/reference)を使用してローカル環境で、またはアプリ内のモジュールエディター上でフィールドを追加できます。[テーマ](/cms/start-building/building-blocks/overview)にフィールドを追加するには、CLIを使用してテーマの`fields.json`ファイルをローカル環境で更新する必要があります。

### HubSpot CLI

モジュールフィールドとテーマフィールドを[ローカル環境で構築](/developer-tooling/local-development/hubspot-cli/install-the-cli)する場合、モジュールまたはテーマのフォルダー内にある`fields.json`ファイル経由で編集できます。モジュールの場合、[`hs create module`](/developer-tooling/local-development/hubspot-cli/reference)コマンドを使用すると、このファイルが自動作成されます。モジュールエディターで利用可能な全てのフィールドオプションは、`fields.json`ファイルで追加または編集できるプロパティーとして使用できます。これには、リピーターフィールド、グループ、条件が含まれます。ローカル編集の利点の1つとして、[gitのようなバージョン管理システムにモジュールを含め](/cms/start-building/introduction/developer-environment/github-integration)やすくなることが挙げられます。

### モジュールエディター

[デザインマネージャー](/cms/start-building/introduction/developer-environment/design-manager)には組み込みのモジュールエディターUIがあり、モジュールフィールドの[作成](https://knowledge.hubspot.com/ja/design-manager/create-and-edit-modules)、グループ化、[編集](https://knowledge.hubspot.com/ja/design-manager/create-and-edit-modules)に使用できます。モジュールエディターにはモジュールのプレビューがあるため、外観の確認とフィールドのテストが可能です。モジュールは何もないところでは動作しないので、必ず使用予定のテンプレートでテストし、テンプレートレベルのスタイルがモジュールにどのような影響を与えるかを確認する必要があります。なお、ロックされたフォルダーにモジュールが含まれている場合は、この方法で編集できないことに注意しましょう。

<Frame>
  <img src="https://cdn2.hubspot.net/hubfs/53/Module%20Editor-1-1.png" alt="デザインマネージャーのモジュールエディター" />
</Frame>

<Warning>
  **注**: 主にローカル環境で作業し、フィールドの設定にモジュールエディターを使用する場合は、必ず変更を[fetch（フェッチ）](/developer-tooling/local-development/hubspot-cli/reference#fetch)してください。Gitのようなバージョン管理システムを使用する場合には、特に重要です。
</Warning>

## フィールドの横配置

デフォルトでは、コンテンツエディターでモジュールフィールドは縦方向に配置されます。ただし、`fields.json`ファイルのフィールドに`display_width`プロパティーを追加し、値を`half_width`に設定して、モジュールフィールドを横並びに配列することもできます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2021/Developer/side-by-side-modules0.png" alt="横並びのモジュール" />
</Frame>

`display_width`を`half_width`に設定した単一フィールドは、コンテンツエディターでは半分の幅で表示されます。`fields.json`内でこのフィールドの上または下にあるフィールドを`half_width`に設定すると、フィールドが横並びに配置されます。

```json theme={null}
// Example module fields.json file
[
  {
    "name": "number_field",
    "label": "Number",
    "required": false,
    "locked": false,
    "display": "slider",
    "min": 1,
    "max": 10,
    "step": 1,
    "type": "number",
    "prefix": "",
    "suffix": "",
    "default": null,
    "display_width": "half_width"
  },
  {
    "label": "Description",
    "name": "description",
    "type": "text",
    "required": true,
    "default": "Add a description",
    "display_width": "half_width"
  }
]
```

## フィールドグループ

フィールドが互いに関連している場合、視覚的にグループ化することが適切な場合が少なくありません。これは、モジュールとテーマの両方でサポートされているフィールドグループを作成すれば実現できます。ローカルでフィールドグループを作成するには、`fields.json`で`"group"`という`type`のオブジェクトを作成します。次に、グループ化したいフィールドを格納する`children`配列を含めます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023_2024/field-group-example-expanded-burrata.png" alt="シンプルなフィールドグループのサンプル" />
</Frame>

```json theme={null}
[
  {
    "id": "9c00985f-01db-ac5d-73f5-80ed6c0c7863",
    "name": "my_text",
    "display_width": null,
    "label": "Text",
    "required": true,
    "locked": false,
    "validation_regex": "",
    "allow_new_line": false,
    "show_emoji_picker": false,
    "type": "text",
    "default": "Add text here"
  },
  {
    "type": "group",
    "name": "recipe_summary_group",
    "label": "Recipe summary",
    "expanded": true,
    "inline_help_text": "Summarize the recipe (title and description)",
    "children": [
      {
        "type": "text",
        "label": "Recipe title",
        "name": "recipe_title",
        "placeholder": "Burrata salad"
      },
      {
        "type": "text",
        "label": "Recipe description",
        "name": "recipe_description",
        "placeholder": "fig mostarda, hazelnuts, arugula, vincotto, prosciutto, toasted sourdough"
      }
    ]
  }
]
```

最初の`children`パラメーター内に別の`"group"`タイプのオブジェクトを追加することで、グループ内にさらにフィールドグループを作成できます。それから、上記と同じ方法でフィールドグループを構築し、`children`を使ってフィールドを格納します。フィールドグループは3レベルでネストできます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023_2024/field-group-example-secondary-group.png" alt="2次グループを含むフィールドグループ" />
</Frame>

```json theme={null}
[
  {
    "type": "group",
    "name": "recipe_summary_group",
    "label": "Recipe summary",
    "inline_help_text": "Summarize the recipe (title and description)",
    "display": "inline",
    "children": [
      {
        "type": "text",
        "label": "Recipe title",
        "name": "recipe_title",
        "placeholder": "Burrata salad"
      },
      {
        "type": "text",
        "label": "Recipe description",
        "name": "recipe_description",
        "placeholder": "fig mostarda, hazelnuts, arugula, vincotto, prosciutto, toasted sourdough"
      },
      {
        "type": "group",
        "name": "secondary_group",
        "label": "Secondary group",
        "expanded": false,
        "children": [
          {
            "name": "bg_color",
            "label": "Background color",
            "sortable": false,
            "required": false,
            "locked": false,
            "type": "color",
            "default": {
              "color": "#ff0000",
              "opacity": 100
            }
          }
        ]
      }
    ]
  }
]
```

#### フィールドグループの表示オプション

次のフィールドグループの表示動作をカスタマイズできます。

* **展開**: デフォルトでは、フィールドグループはエディター内で折りたたまれた状態で表示されます。ネストされたグループを含むグループはドリルダウンボタンとして表示され、独自のビューで開き、最も内側のグループには区切り線が表示されます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023_2024/field-group-collapsed-default.png" alt="デフォルト折りたたみグループ" />
</Frame>

* **表示タイプ**: デフォルトでは、ネストされたグループを含まないグループは、子グループの周囲に視覚的な区切り線が付いた折りたたみ可能なセクションとして表示されます。ネストされたグループを含むグループはドリルダウンボタンとして表示され、独自のビューで開き、最も内側のグループは区切り線付きで表示されます。
* **グループアイコン**: 必要に応じて、ラベルの左側に表示する「Font Awesome」アイコンを含めることができます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023_2024/field-group-icon-example.png" alt="アイコンの例" />
</Frame>

```json theme={null}
[
  {
    "type": "group",
    "name": "recipe_summary_group",
    "label": "Recipe summary",
    "display": "drilldown",
    "inline_help_text": "Summarize the recipe (title and description)",
    "icon": {
      "name": "star",
      "set": "fontawesome-5.14.0",
      "type": "SOLID"
    },
    "children": [
      {
        "type": "text",
        "label": "Recipe title",
        "name": "recipe_title",
        "placeholder": "Burrata salad"
      },
      {
        "type": "text",
        "label": "Recipe description",
        "name": "recipe_description",
        "placeholder": "fig mostarda, hazelnuts, arugula, vincotto, prosciutto, toasted sourdough"
      }
    ]
  }
]
```

| パラメーター     | タイプ    | 説明                                                                                                                                                                                                                                                                                                      |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `display`  | 文字列    | フィールドグループの表示スタイル。次のいずれかになります。<ul><li>`drilldown`：折りたたまれたグループに、子グループを独自のパネルで開くためのボタンが表示されます。これは、ネストされたグループを含むグループのデフォルト表示です。</li><li>`accordion`：折りたたまれたグループの下に、子グループを展開するボタンを展開可能なセクションとして表示します。これは、ネストされたグループがないグループのデフォルト表示です。</li><li>`inline`：グループと子グループをインラインで表示し、グループを折りたたむオプションはありません。</li></ul> |
| `icon`     | オブジェクト | ラベルの左側にアイコンを追加します。次のパラメーターがあります。<ul><li>`name`：Font Awesomeアイコンの識別子。</li><li>`set`：Font Awesomeの[アイコンセット](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#icon)（英語）。</li><li>`type`：アイコンのスタイル（例：`SOLID`、`REGULAR`）。</li></ul>                                               |
| `expanded` | ブール値   | フィールドグループがデフォルトで展開されるかどうかを指定します。                                                                                                                                                                                                                                                                        |

#### フィールドグループ内のフィールド値の出力

フィールドグループでは、出力するフィールド値を含むディクショナリー（辞書型）が作成されます。フィールドグループをネストした場合、ネストされたフィールドグループは外側のフィールド グループ ディクショナリー内にディクショナリーとして格納されます。このデータにアクセスするには、状況に応じてルートのテーマまたはモジュール変数からツリー内を走査する必要があります。

<CodeGroup>
  ```html example.html theme={null}
  <div>
  {# printing a value from a field group `recipe_summary` is the field group,
  `title` is the text field. #} {{module.recipe_summary.title}}
  </div>
  ```

  ```css example.css theme={null}
  /* Printing a Font field's color value, when the font field is within a field group.
  `typography` is the field group, `h1_font` is the field */
  h1{
  color: {{ theme.typography.h1_font.color }};
  }
  ```
</CodeGroup>

#### フィールドグループの特集項目

フィールドグループが繰り返される状況では、出現するフィールドグループのうち1つ以上をキービジュアル項目として指定できます。これにより、項目を個別にスタイル設定して目立たせることができます。例えば、強調表示したいおすすめの製品を表示する製品ページで特に便利です。

フィールドグループあたりの特集項目の最大数を指定できます。その後、制作担当者はエディターで必要に応じて項目を特集項目としてマークできます。

<Frame>
  <img src="https://knowledge.hubspot.com/hubfs/Knowledge_Base_2023_2024/cms-field-group-featured-in-app%20(1).png" alt="cms-field-group-featured-in-app (1)" />
</Frame>

)

フィールドグループ内で特集項目を有効にするには、フィールドグループの設定に`group_occurrence_meta`プロパティーを含めます。このプロパティーには次のプロパティーが格納されます。

* `featured_enabled`：`true`に設定すると、特集項目が有効になります。
* `featured_limit`：使用できる特集項目の最大数。

フィールドグループには`occurrence`プロパティーも含める必要があります。

```json theme={null}
// Field group example
{
  "label": "Card",
  "name": "card",
  "type": "group",
  "occurrence": {
    "default": 2,
    "min": 1,
    "sorting_label_field": "card.title"
  },
  "group_occurrence_meta": {
    "featured_enabled": true,
    "featured_limit": 3
  },
  "children": [
    {
      "label": "Image",
      "name": "image",
      "type": "image",
      "responsive": true,
      "resizable": true,
      "show_loading": true,
      "default": {
        "loading": "lazy"
      }
    },
    {
      "label": "Content",
      "name": "text",
      "type": "richtext",
      "enabled_features": [
        "advanced_emphasis",
        "alignment",
        "block",
        "emoji",
        "font_family",
        "font_size",
        "lists",
        "standard_emphasis"
      ],
      "default": "<h3>This is a title</h3><p>Contextual advertising can be profitable. It can either pay for your hosting and maintenance costs for you website or it can pay for a lot more.</p>"
    }
  ],
  "default": [
    {
      "image": {
        "loading": "lazy"
      },
      "text": "<h3>This is a title</h3><p>Contextual advertising can be profitable. It can either pay for your hosting and maintenance costs for you website or it can pay for a lot more.</p>"
    },
    {
      "image": {
        "loading": "lazy"
      },
      "text": "<h3>This is a title</h3><p>Contextual advertising can be profitable. It can either pay for your hosting and maintenance costs for you website or it can pay for a lot more.</p>"
    }
  ]
}
```

繰り返しグループ内の項目がキービジュアルであるかどうかを確認するには、`hs_meta`プロパティーを照会します。以下のコードでは、[forループ](https://developers.hubspot.jp/docs/cms/reference/hubl/loops)を使用して、特集項目に設定されているフィールドグループ項目を確認し、各項目のタイトルを`h3`ヘッダーとして表示しています。

`{{ repeated_group_item.hs_meta.occurrence.featured }}`

```hubl theme={null}
<div>
  <h2>Check out this week's featured items:</h2>
  <div>
    {% for item in module.card %}
        {% if item.hs_meta.occurrence.featured %}
            <h3>{{item.title}}</h3>
        {% endif %}
    {% endfor %}
  </div>
</div>
```

## スタイルフィールド

スタイルフィールドは、モジュールまたはテーマの`fields.json`ファイルの特殊なフィールド グループ タイプで、これによって制作担当者がモジュールやテーマのスタイルをページエディターとテーマエディター上で制御できるようになります。モジュールまたはテーマにスタイルフィールドを追加する方法を以下に示します。[スタイルフィールドの使用と整理に関するベストプラクティス](https://developers.hubspot.jp/docs/cms/best-practices/fields)をご参照ください。

### モジュールのスタイルフィールド

モジュールに追加したスタイルフィールドは、モジュール編集時のページエディターの［スタイル］タブに表示されます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2021/Developer/style-field-module-editor0.png" alt="スタイルフィールド-モジュールエディター" />
</Frame>

スタイルフィールドをモジュールの`fields.json`ファイルに追加する場合は、全てのフィールドを1つのスタイルグループ内に追加します。ただし、次のようにこのグループ内に複数のグループを含めることができます。

```json theme={null}
// Module style fields
[
  {
    "type": "group",
    "name": "styles",
    "tab": "STYLE",
    "children": [
      {
        "name": "img_spacing",
        "label": "Spacing around image",
        "required": false,
        "type": "spacing",
        "default": {
          "padding": {
            "top": {
              "value": 10,
              "units": "px"
            },
            "bottom": {
              "value": 10,
              "units": "px"
            },
            "left": {
              "value": 10,
              "units": "px"
            },
            "right": {
              "value": 10,
              "units": "px"
            }
          },
          "margin": {
            "top": {
              "value": 10,
              "units": "px"
            },
            "bottom": {
              "value": 10,
              "units": "px"
            }
          }
        }
      }
    ]
  }
]
```

モジュールのスタイルフィールドとして使用できるフィールドを以下に示します。各フィールドタイプについては、[モジュールとフィールドタイプのガイド](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields)をご確認ください。

* [位置合わせ](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#alignment)
* [グラデーション](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#gradient)
* [間隔](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#spacing)
* [背景画像](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#background-image)
* [境界線](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#border)
* [ブール値](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#boolean)
* [選択](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#choice)
* [数値](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#number)
* [カラー](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#color)
* [アイコン](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#icon)
* [画像](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#image)
* [フォント](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#font)
* [テキストの位置合わせ](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#text-alignment)

詳しくは[モジュールとテーマのフィールドタイプ](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields)をご覧ください。

モジュールの`fields.json`ファイル内のスタイルフィールドの例については、[CMSボイラープレート](https://github.com/HubSpot/cms-theme-boilerplate/blob/main/src/modules/card.module/fields.json)（英語）をご参照ください。

### テーマのスタイルフィールド

テーマに追加したスタイルフィールドは、テーマエディターの左のサイドバーに表示されます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2021/Developer/style-field-theme-editor0.png" alt="スタイルフィールド-テーマエディター" />
</Frame>

以下のように、テーマの`fields.json`ファイル内にある全てのスタイルフィールドは、テーマエディターの左のサイドバーに追加され、スタイルグループに追加する必要はありません。

```json theme={null}
// Theme style fields
[
  {
    "label": "Global colors",
    "name": "global_colors",
    "type": "group",
    "children": [
      {
        "label": "Primary",
        "name": "primary",
        "type": "color",
        "visibility": {
          "hidden_subfields": {
            "opacity": true
          }
        },
        "default": {
          "color": "#494A52"
        }
      },
      {
        "label": "Secondary",
        "name": "secondary",
        "type": "color",
        "visibility": {
          "hidden_subfields": {
            "opacity": true
          }
        },
        "default": {
          "color": "#F8FAFC"
        }
      }
    ]
  },
  {
    "label": "Global fonts",
    "name": "global_fonts",
    "type": "group",
    "children": [
      {
        "label": "Primary",
        "name": "primary",
        "type": "font",
        "visibility": {
          "hidden_subfields": {
            "size": true,
            "styles": true
          }
        },
        "inherited_value": {
          "property_value_paths": {
            "color": "theme.global_colors.primary.color"
          }
        },
        "default": {
          "fallback": "sans-serif",
          "font": "Lato",
          "font_set": "GOOGLE"
        }
      },
      {
        "label": "Secondary",
        "name": "secondary",
        "type": "font",
        "visibility": {
          "hidden_subfields": {
            "size": true,
            "styles": true
          }
        },
        "inherited_value": {
          "property_value_paths": {
            "color": "theme.global_colors.primary.color"
          }
        },
        "default": {
          "fallback": "serif",
          "font": "Merriweather",
          "font_set": "GOOGLE"
        }
      }
    ]
  },
  {
    "name": "branding_color",
    "label": "branding_color",
    "type": "color",
    "default": {
      "color": "#3b7bc0", "opacity": 60
    },
    "inherited_value": {
      "property_value_paths": {
        "color": "brand_settings.primaryColor"
       }
    }
  },
  {
    "name": "secondary_branding_color",
    "label": "Secondary Branding color",
    "type": "color",
    "default": {
      "color": "#ff6b6b", "opacity": 60
    },
    "inherited_value": {
      "property_value_paths": {
        "color": "brand_settings.colors[2]"
         }
       }
     }
   ]
  }
]
```

テーマのスタイルフィールドとして使用できるフィールドを以下に示します。各フィールドタイプについては、[モジュールとフィールドタイプのガイド](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields)をご確認ください。

* [ブール値](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#boolean)
* [境界線](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#border)
* [選択](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#choice)
* [カラー](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#color)
* [フォント](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#font)
* [画像](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#image)
* [数値](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#number)
* [間隔](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#spacing)

詳しくは[モジュールとテーマのフィールドタイプ](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields)をご覧ください。

テーマの`fields.json`ファイル内のスタイルフィールドの例については、[CMSボイラープレート](https://github.com/HubSpot/cms-theme-boilerplate/blob/main/src/fields.json)（英語）をご参照ください。

<Warning>
  **注**: マーケットプレイスプロバイダーは、既存のモジュールの既存のコンテンツフィールドをスタイルフィールドで置き換えることは<u>できません</u>。`fields.json`ファイルのフィールド階層を変更すると、既存のモジュールインスタンスのデータが失われることがあります。代わりに、新しいスタイルフィールドの追加、またはフィールドを適切にグループ化した新しいリストの作成ができます。これにより、貴社の更新によって、貴社のテーマを利用している顧客のコンテンツが破損するような変更は避けられます。以前のモジュールの移行パスについては、[HubSpotアイデアフォーラム](https://community.hubspot.com/t5/HubSpot-Ideas/Create-a-path-to-make-it-possible-to-migrate-existing-fields-to/idi-p/450311#M85938)（英語）をご参照ください。
</Warning>

### 生成されるCSS

一部のスタイルフィールドには、フィールドの値に基づいてCSSを直接出力する仕組みがあります。これは、グラデーションなどの複雑なスタイルを制御できるフィールドの場合に特に役立ちます。次のスタイルフィールドでは、生成された`.css`プロパティーが使用されます。

* [背景画像](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#background-image)
* [境界線](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#border)
* [カラー](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#color)
* [フォント](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#font)
* [グラデーション](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#gradient)
* [間隔](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#spacing)
* [テキストの位置合わせ](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#text-alignment)

```hubl theme={null}
{% require_css %}
<style>
{% scope_css %}
  .team-member {
  {% if module.style.gradient.css %}
  background: {{ module.style.gradient.css }};
  {% endif %}
  {{ module.style.bg_img.css }}
  {{ module.style.spacing.css }}
  {{ module.style.border.css }}
  }
{% end_scope_css %}
</style>
{% end_require_css %}
```

## リピーター

情報を形成するモジュールを作成する際には、繰り返し使用される情報があります。例えば、レシピモジュールに「材料」のフィールドがあるとします。ほとんどのレシピの材料は1つにとどまりません。リッチ テキスト フィールドを利用した場合、スタイルの一貫性を確保したり、材料別の機能を追加したりすることはできなくなります。このような状況ではリピーターが役に立ちます。HubSpotには繰り返しフィールドと繰り返しグループという2つの形式のリピーターがあります。

### 繰り返しフィールド

<DndSection>
  <DndModule numCols={7}>
    <div>
      繰り返しフィールドは通常のフィールドですが、制作担当者がフィールドのインスタンスを追加、削除、再配置できます。上記のレシピモジュールの例では、各材料を繰り返しテキストフィールドにできます。
    </div>
  </DndModule>

  <DndModule numCols={5}>
    <Frame>
      <img src="https://cdn2.hubspot.net/hubfs/53/repeater%20field.png" alt="繰り返しフィールド" />
    </Frame>
  </DndModule>
</DndSection>

これにより、制作担当者は必要な数の材料を追加できます。開発者の観点からは、ループ処理によって材料のリストを出力できる配列を使用して、必要な書式と機能を適用できます。

繰り返しフィールドは非常にシンプルな状況に最適です。一般的には、[繰り返しグループ](#repeating-groups)が適切なケースが多くあります。

<Warning>
  **注**: 現在のところ、繰り返しフィールドでデフォルトの順序を設定することはできません。
</Warning>

#### Fields.json内の繰り返しフィールド

```json theme={null}
// Repeating field example
{
  "name": "ingredient",
  "label": "Ingredient",
  "required": false,
  "locked": false,
  "occurrence": {
    "min": 1,
    "max": null,
    "sorting_label_field": null,
    "default": 1
  },
  "allow_new_line": false,
  "show_emoji_picker": true,
  "type": "text",
  "default": ["1 cup water"]
}
```

#### モジュールのHTML+HubLでの項目のループ

```html theme={null}
<!--Looping through a repeating field-->
<ul>
  {% for item in module.ingredient %}
  <li>{{ item }}</li>
  {% endfor %}
</ul>
```

### 繰り返しグループ

<DndSection>
  <DndModule numCols={7}>
    <div>
      繰り返しグループは、繰り返しに対応したフィールドグループです。繰り返しグループを使用すると、制作担当者がフィールドのグループを追加、削除、再配置できるようになります。レシピモジュールの例で、材料リストをショッピングリスト機能と連携する状況を考えてみます。
    </div>
  </DndModule>

  <DndModule numCols={5}>
    <Frame>
      <img src="https://cdn2.hubspot.net/hubfs/53/Screen%20Shot%202020-02-26%20at%205.19.14%20PM.png" alt="フィールドの繰り返しグループ" />
    </Frame>
  </DndModule>
</DndSection>

ショッピングリストでは、材料の数量が重要です。数量がテキストフィールドに入力されると同時に、このモジュールがテキストフィールドを解析して、材料から数量が正常に分離されるようにする必要があります。そこで役立つのが、繰り返しグループです。こうしたフィールドの出力に対し、ループ処理を行うことができます。

#### Fields.json内の繰り返しグループ

```json theme={null}
// Repeating field group example
{
  "id": "ingredients",
  "name": "ingredients",
  "label": "Ingredients",
  "required": false,
  "locked": false,
  "occurrence": {
    "min": 1,
    "max": null,
    "sorting_label_field": "ingredients.ingredient",
    "default": null
  },
  "children": [
    {
      "id": "ingredients.ingredient",
      "name": "ingredient",
      "label": "Ingredient",
      "required": false,
      "locked": false,
      "validation_regex": "",
      "allow_new_line": false,
      "show_emoji_picker": false,
      "type": "text",
      "default": "Water"
    },
    {
      "id": "ingredients.quantity",
      "name": "quantity",
      "label": "Quantity",
      "required": false,
      "locked": false,
      "display": "text",
      "min": 0,
      "step": 1,
      "type": "number",
      "default": 1
    },
    {
      "id": "ingredients.measurement",
      "name": "measurement",
      "label": "Measurement",
      "help_text": "Unit of measurement (cups, tbsp, etc.)",
      "required": false,
      "locked": false,
      "allow_new_line": false,
      "show_emoji_picker": false,
      "type": "text",
      "default": "cups"
    }
  ],
  "type": "group",
  "default": [
    {
      "ingredient": "Water",
      "quantity": 1,
      "measurement": "cups"
    }
  ]
}
```

#### モジュール内の繰り返しフィールドのループ処理

```html theme={null}
<h2>Ingredients</h2>
<ul>
  {% for ingredient in module.ingredients %}
  <li>
    <button
      data-quantity="{{ ingredient.quantity }}"
      data-unit="{{ ingredient.measurement }}"
      data-ingredient="{{ ingredient.ingredient }}"
    >
      Add to cart
    </button>
    {{ ingredient.quantity }} {{ ingredient.measurement }} {{ ingredient.ingredient }}
  </li>
  {% endfor %}
</ul>
```

### リピーターオプション

<DndSection>
  <DndModule numCols={7}>
    <div>
      編集時の利便性を向上すると共に、プログラム側で未対応の値が入力できないように、繰り返しフィールドや繰り返しグループには、制作担当者による追加可能項目数の最小値と最大値を設定できます。

      繰り返しグループでは、リピーターを表示するときに、その項目のラベルとして機能するフィールドを設定することもできます。
    </div>
  </DndModule>

  <DndModule numCols={5}>
    <Frame>
      <img src="https://cdn2.hubspot.net/hubfs/53/Screen%20Shot%202020-02-26%20at%205.35.29%20PM.png" alt="最大出現数" />
    </Frame>
  </DndModule>
</DndSection>

```json theme={null}
"occurrence" : {
    "min" : 1,
    "max" : 4,
    "sorting_label_field" : "ingredients.ingredient",
}
```

| パラメーター                | タイプ | 説明                                                                  | デフォルト値 |
| --------------------- | --- | ------------------------------------------------------------------- | ------ |
| `max`                 | 整数  | このグループの最大出現回数。制作担当者がUIにこの数以上のアイテムを追加できないようにします。                     | `null` |
| `min`                 | 整数  | このフィールドグループの最小出現数。UIに表示されるアイテムがこの数より少なくなるのを防ぎます。                    | `null` |
| `sorting_label_field` | 文字列 | ドラッグ操作可能なカード上のUIに表示するテキストを取得できるフィールドのIDです。デフォルト値は、グループ内の最初のフィールドです。 |        |

## 継承フィールド

`inherited_value`プロパティーは、他のフィールドからデフォルト値を継承するようにフィールドを設定できます。フィールドのデフォルト値全体を別のフィールド値から設定するには、`default_value_path`にターゲットフィールドのフィールド名パスを指定します。`default_value_path`を設定すると、フィールドに設定された`default`は全て無視されます。

他のフィールドの値にアクセスするには、モジュールのHubLコードでのアクセスと同様に、パスの先頭に`module.`を含める必要があります。

```json theme={null}
// Inherited fields
{
  "name": "body_font",
  "type": "font",
  "default": {
    "font": "Helvetica",
    "color": "#C27BA0"
  }
},
{
  "name": "h1_font",
  "type": "font",
  "default": {},
  "inherited_value": {
    "default_value_path": "module.body_font",
    "property_value_paths" : {
      "font": "module.body_font.font",
      "font_set": "module.body_font.font_set"
    }
  }
}
```

<Info>
  フォントファミリーは`font`と`font_set`の組み合わせによって決まるため、フォントフィールドの継承にはこの両方を含める必要があります。詳しくは[フォントフィールド](https://developers.hubspot.jp/docs/cms/reference/fields/module-theme-fields#%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88)をご確認ください。
</Info>

複雑なフィールド（値がオブジェクトのフィールド）の場合、ユーザーは`property_value_path`に継承するプロパティーを細かく指定できます。`inherited_value`で参照されるパスにも、複雑なフィールドのフィールド値からのキーを含めることができます。

例えば、色フィールドには、色自体と不透明度を含むオブジェクト値があります。そのため、不透明度なしで色自体の値を取得するには、パスの末尾に`.color`を指定します。例えばフォントフィールドは、個別の色フィールドから色だけを継承できます。

```json theme={null}
// Inherited fields with objects
{
  "name": "secondary_color",
  "type": "color",
  "default": {
    "color": "#C27BA0",
    "opacity": 100
  }
},
{
  "name": "h1_font",
  "type": "font",
  "default": {
    "font": "Helvetica",
    "size": 12,
    "size_unit": "px"
  },
  "inherited_value": {
    "property_value_paths": {
      "color": "module.secondary_color.color"
    }
  }
}
```

`default_value_path`と`property_value_paths`の効果を組み合わせて、あるフィールドからデフォルト値を継承しながら、別のフィールドから特定のプロパティー値を継承することもできます。

```json theme={null}
// combining default_value_path and property_value_paths
{
  "name": "body_font",
  "type": "font",
  "default": {
    "font": "Helvetica",
    "color": "#000000"
  }
},
{
  "name": "secondary_color",
  "type": "color",
  "default": {
    "color": "#C27BA0",
    "opacity": 100
  }
},
{
  "name": "h1_font",
  "type": "font",
  "default": {},
  "inherited_value": {
    "default_value_path": "module.body_font",
    "property_value_paths": {
      "color": "module.secondary_color.color"
    }
  }
}
```

別のフィールドから継承したフィールドが、ページまたはテーマ設定によって直接変更される場合、制御元のフィールドとの接続は失われます。このフィールドの値に、`default_value_path`または`property_value_paths`によって関連付けられた他のフィールドから影響を与えることはできなくなります。

## フィールドの可視性

カスタムモジュールとテーマフィールドを定義する際に、`fields.json`ファイル内のフィールドに`visibility`オブジェクトを追加することで、フィールドが表示される条件を構成できます。例えば、サンキューメッセージが選択されているときにはリッチテキスト領域を表示する一方で、リダイレクトが選択されているときはページセレクターを表示するようにフォームモジュールを設定できます。

表示条件は`controlling_field_path`の値を基準に設定することも、`property`パラメーターを使用してフィールド内の特定のプロパティーを基準に設定することもできます。また、個々のフィールドに表示条件を適用したり、フィールドのグループに表示条件を適用して、そのグループ内の全ての要素の表示条件を管理したりすることもできます。

```json theme={null}
"visibility" : {
 "controlling_field_path" : "field_name",
 "controlling_value_regex" : "regular_expression_in_controlling_field",
 "property": "src",
 "operator" : "EQUAL"
  }
```

| パラメーター                    | タイプ | 説明                                                                                                                                                                                                                                                               |
| ------------------------- | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `controlling_field_path`  | 文字列 | 表示条件を制御するフィールドのパス。<ul><li>フィールドがフィールドグループ内にネストされていない場合は、フィールドの名前（つまり`field_name`）を使用します。</li><li>グループ内にネストされたフィールドの場合、パスはピリオドで区切られたグループ化構造と一致する必要があります。例：<ul><li>`field_group_name.field_name`</li><li>`parent_group.child_group.field_name`</li></ul></li></ul> |
| `controlling_value_regex` | 文字列 | フィールドを表示するために存在する必要がある制御フィールドの正規表現。正規表現は（部分文字列ではなく）文字列全体に一致する必要があり、大文字と小文字も区別されます。                                                                                                                                                                               |
| `operator`                | 文字列 | `controlling_value_regex`値との一致方法を定義する演算子。次のいずれかの演算子を使用できます。<ul><li>`NOT_EQUAL`</li><li>`EQUAL`</li><li>`EMPTY`</li><li>`NOT_EMPTY`</li><li>`MATCHES_REGEX`</li></ul>                                                                                             |
| `property`                | 文字列 | 文字列ターゲットフィールドの特定のプロパティーに基づいて表示条件を設定します。例えば、画像フィールドの`src`プロパティーが特定の値と等しい場合に、このフィールドが表示されるようにできます。デフォルトでは、このフィールドに値が指定されていない場合、表示条件は文字列に変換された`controlling_value_regex`値に基づくことになります。                                                                                |

`visibility`オブジェクト内に`occurrence_options`オブジェクトを含めると、繰り返されるフィールドの値数をターゲットにすることもできます。このオブジェクトには、比較する`count`と`operator`の定義を含める必要があります。例えば、別の繰り返しフィールドに少なくとも2つの項目がある場合にのみテキストフィールドを表示するには、`visibility`を次のように定義します。

```json theme={null}
[
  {
    "type": "group",
    "name": "ingredients",
    "label": "Recipe ingredients",
    "display": "drilldown",
    "children": [
      {
        "name": "ingredient",
        "label": "Ingredient",
        "occurrence": {
          "min": 1,
          "max": null,
          "default": 1
        },
        "type": "text",
        "default": ["1 cup water"]
      },
      {
        "type": "text",
        "label": "Conditional field",
        "name": "conditional_field",
        "visibility": {
          "controlling_field_path": "ingredients.ingredient",
          "occurrence_options": {
            "count": 2,
            "operator": "GREATER_THAN_OR_EQUAL"
          }
        }
      }
    ]
  }
]
```

次のいずれかの`operater`の値を使用できます。

* `"NOT_EQUAL"`
* `"EQUAL"`
* `"EMPTY"`
* `"NOT_EMPTY"`
* `"GREATER_THAN"`
* `"GREATER_THAN_OR_EQUAL"`
* `"LESS_THAN"`
* `"LESS_THAN_OR_EQUAL"`

### 高度な可視性

`visibility`属性で同時に複数の条件をサポートすることはできません。複数の演算子を使用して複数の条件を追加し、演算の順序も指定するには、`advanced_visibility`を使用します。

```json theme={null}
"visibility_rules" : "ADVANCED",
"advanced_visibility" : {
   "boolean_operator" : "AND",
   "criteria" : [{
     "controlling_field_path" : "field_name",
     "controlling_value_regex" : "regular_expression_in_controlling_field",
      "operator" : "MATCHES_REGEX"
    },
    {
     "controlling_field_path" : "field_name",
     "controlling_value_regex" : "regular_expression_in_controlling_field",
     "operator" : "EQUAL"
    }]
}
```

| パラメーター                    | タイプ | 説明                                                                                                                                                                                                                                                                 |
| ------------------------- | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `visibility_rules`        | 文字列 | デフォルトでは、このパラメーターの値は`SIMPLE`に設定されます。`advanced_visibility`を使用する場合は、`ADVANCED`に設定します。                                                                                                                                                                                 |
| `boolean_operator`        | 文字列 | 条件付き基準のブール演算子。`AND`または`OR`のいずれかにできます。                                                                                                                                                                                                                              |
| `criteria`                | 配列  | フィールドを表示するために一致する必要がある条件付き基準を定義する、visibilityオブジェクトからなる配列。                                                                                                                                                                                                          |
| `controlling_field_path`  | 文字列 | 表示条件を制御するフィールドのドットパス。<ul><li>フィールドがフィールドグループ内にネストされていない場合は、フィールドの名前（つまり`field_name`）を使用します。</li><li>グループにネストされたフィールドの場合、パスはピリオドで区切られたグループ化構造と一致する必要があります。例：<ul><li>`field_group_name.field_name`</li><li>`parent_group.child_group.field_name`</li></ul></li></ul> |
| `controlling_value_regex` | 文字列 | フィールドを表示するために一致する必要がある、制御フィールドの値。`MATCHES_REGEX`演算子を使用する場合、正規表現は（部分文字列ではなく）文字列全体に一致する必要があり、大文字と小文字も区別されます。`controlling_field_path`が設定されている一方、`controlling_value_regex`は設定されていないフィールドは、制御フィールドの値がnullでも空白でもない場合に表示されます。                                             |
| `operator`                | 文字列 | `controlling_value_regex`値との一致方法を定義する演算子。次のいずれかの演算子を使用できます。<ul><li>`NOT_EQUAL`</li><li>`EQUAL`</li><li>`EMPTY`</li><li>`NOT_EMPTY`</li><li>`MATCHES_REGEX`</li></ul>`MATCHES_REGEX`を使用する場合は、正規表現の構文が必要です。                                                          |

一例として、以下に[デフォルトの支払いモジュール](https://developers.hubspot.jp/docs/cms/reference/modules/default-modules)の最初の部分を記載します。完全なコードを確認するには、HubSpotでこのモジュールを複製してからローカル環境にダウンロードして、モジュールの`fields.json`ファイルを表示してください。

```json theme={null}
[
  {
    "id": "payment",
    "name": "payment",
    "display_width": null,
    "label": "Payment",
    "required": true,
    "locked": false,
    "type": "payment",
    "default": {
      "id": null,
      "properties": {}
    }
  },
  {
    "id": "checkout_location",
    "name": "checkout_location",
    "display_width": null,
    "label": "Checkout behavior",
    "required": false,
    "locked": false,
    "visibility": {
      "controlling_field_path": "payment",
      "controlling_value_regex": "id\":\\d+",
      "operator": "MATCHES_REGEX"
    },
    "display": "radio",
    "choices": [
      ["new_tab", "Open in a new tab"],
      ["overlay", "Sliding overlay"]
    ],
    "type": "choice",
    "default": "new_tab"
  },
  {
    "id": "button_text",
    "name": "button_text",
    "display_width": null,
    "label": "Button text",
    "required": true,
    "locked": false,
    "validation_regex": "",
    "visibility": {
      "controlling_field_path": "payment",
      "controlling_value_regex": "id\":\\d+",
      "operator": "MATCHES_REGEX"
    },
    "allow_new_line": false,
    "show_emoji_picker": false,
    "type": "text",
    "default": "Checkout"
  },
  {
    "id": "icon",
    "name": "icon",
    "display_width": null,
    "label": "Icon",
    "required": false,
    "locked": false,
    "visibility_rules": "ADVANCED",
    "advanced_visibility": {
      "boolean_operator": "AND",
      "criteria": [
        {
          "controlling_field_path": "payment",
          "controlling_value_regex": "id\":\\d+",
          "operator": "MATCHES_REGEX"
        },
        {
          "controlling_field_path": "add_icon",
          "controlling_value_regex": "true",
          "operator": "EQUAL"
        }
      ],
      "children": []
    },
    "children": [
      {
        "id": "icon.icon",
        "name": "icon",
        "display_width": null,
        "label": "Icon",
        "required": true,
        "locked": false,
        "icon_set": "fontawesome-5.0.10",
        "type": "icon",
        "default": {
          "name": "hubspot",
          "type": "SOLID",
          "unicode": "f3b2"
        }
      },
      {
        "id": "icon.position",
        "name": "position",
        "display_width": null,
        "label": "Position",
        "required": true,
        "locked": false,
        "display": "select",
        "choices": [
          ["left", "Left"],
          ["right", "Right"]
        ],
        "type": "choice",
        "default": "left"
      }
    ],
    "tab": "CONTENT",
    "expanded": false,
    "type": "group"
  }
  // rest of fields.json code
]
```

上記のコードによって、次のような動作になります。

最初のフィールド（`payment`）は、コンテンツ制作担当者が特定の支払いリンクを作成するために使用する、必須のフィールド（ドロップダウンメニュー）です。HubSpotでは、コンテンツ制作担当者が最初にこのモジュールをページに追加すると、次のUIが表示されます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2021/Developer/payment-link-selector.png" alt="支払いリンクの選択肢" />
</Frame>

支払いリンクを選択すると、上記のUIの後に続いて3つのフィールド（`checkout_location`、`button_text`、`icon`）が表示されます。このようになるのは、`payment`フィールドによって制御され、paymentフィールドの`id`パラメーターのID値を必要とする`visibility`属性が、これらのフィールドに設定されているためです。

`icon`フィールド自体は`advanced_visibility`を使用しており、`payment`フィールドに支払いリンクが存在し、かつ、`add_icon`チェックボックスがオンにされている場合にのみ表示されます。

`fields.json`内で可視性を設定するだけでなく、デザインマネージャーでフィールドの「表示条件」オプションを編集して可視性を設定することもできます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2021/Developer/display-conditions-property.png" alt="表示条件オプション" />
</Frame>

デザインマネージャーで表示条件を設定した後は、[CLIを使用](/developer-tooling/local-development/hubspot-cli/reference#fetch)してこのモジュールを[フェッチ](/developer-tooling/local-development/hubspot-cli/install-the-cli)し、モジュールの`fields.json`ファイル内で`visibility`属性を確認できます。

## 条件付きフィールドの無効化

フィールドに条件を追加して、指定された条件が満たされたときに編集不可にすることができます。フィールドを無効にした場合、コンテンツエディターでコンテキストを提供するために、フィールドの上に表示するメッセージを設定することもできます。

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023/Screenshot%202023-05-23%20at%204.10.28%20PM.png" alt="Screenshot 2023-05-23 at 4.10.28 PM" />
</Frame>

条件とメッセージは、フィールドの`disabled_controls`オブジェクトで設定されます。フィールドを編集可能にするための条件は、`rules`オブジェクト内で設定され、[advanced\_visibility](#field-visibility)と同じ形式に従います。

以下のコードは、`rules`基準の単純な実装と高度な実装の両方を示しています。

* `simple_page`フィールドには、`text_field`が`testing`に設定されている場合にフィールドを無効にするロジックが含まれています。
* `fancy_page`フィールドには、`text_field`または`text_field_2`のいずれかがそれぞれ`testing`と`testing2`に等しく<u>ない</u>値に設定されている場合にフィールドを無効にするロジックが含まれています。

```json theme={null}
// example fields.json
[
  {
    "type": "text",
    "name": "text_field",
    "label": "Text field"
  },
  {
    "type": "text",
    "name": "text_field_2",
    "label": "Text field 2"
  },
  {
    "type": "page",
    "label": "Simple Page",
    "name": "simple_page",
    "disabled_controls": {
      "message": "This field is disabled",
      "rules": {
        "criteria": [
          {
            "controlling_field_path": "text_field",
            "operator": "EQUAL",
            "controlling_value_regex": "testing"
          }
        ]
      }
    }
  },
  {
    "type": "page",
    "label": "Fancy Page",
    "name": "fancy_page",
    "disabled_controls": {
      "message": "This field is disabled",
      "rules": {
        "boolean_operator": "OR",
        "criteria": [
          {
            "controlling_field_path": "text_field",
            "operator": "NOT_EQUAL",
            "controlling_value_regex": "testing"
          },
          {
            "controlling_field_path": "text_field_2",
            "operator": "NOT_EQUAL",
            "controlling_value_regex": "testing2"
          }
        ]
      }
    }
  }
]
```

| パラメーター                    | タイプ    | 説明                                                                                                                                                                                                                                                                 |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `message`                 | 文字列    | フィールドが無効な場合にコンテンツエディターに表示するメッセージ。                                                                                                                                                                                                                                  |
| `rules`                   | オブジェクト | フィールドの編集を有効にするための条件。                                                                                                                                                                                                                                               |
| `criteria`                | 配列     | フィールドを表示するために満たす必要がある基準を定義する条件オブジェクトの配列。この配列には、`boolean_operator`パラメーターを使用して`AND`または`OR`ロジックで区切られた複数の条件オブジェクトを含めることができます。                                                                                                                                          |
| `boolean_operator`        | 文字列    | 条件付き基準のブール演算子。`AND`または`OR`のいずれかにできます。指定しなかった場合、デフォルトで`AND`になります。                                                                                                                                                                                                   |
| `controlling_field_path`  | 文字列    | 表示条件を制御するフィールドのドットパス。<ul><li>フィールドがフィールドグループ内にネストされていない場合は、フィールドの名前（つまり`field_name`）を使用します。</li><li>グループにネストされたフィールドの場合、パスはピリオドで区切られたグループ化構造と一致する必要があります。例：<ul><li>`field_group_name.field_name`</li><li>`parent_group.child_group.field_name`</li></ul></li></ul> |
| `controlling_value_regex` | 文字列    | フィールドを表示するために一致する必要がある、制御フィールドの値。`MATCHES_REGEX`演算子を使用する場合、正規表現は（部分文字列ではなく）文字列全体に一致する必要があり、大文字と小文字も区別されます。`controlling_field_path`が設定されている一方、`controlling_value_regex`は設定されていないフィールドは、制御フィールドの値がnullでも空白でもない場合に表示されます。                                             |
| `operator`                | 文字列    | `controlling_value_regex`値との一致方法を定義する演算子。次のいずれかの演算子を使用できます。<ul><li>`NOT_EQUAL`</li><li>`EQUAL`</li><li>`EMPTY`</li><li>`NOT_EMPTY`</li><li>`MATCHES_REGEX`</li></ul>`MATCHES_REGEX`を使用する場合は、正規表現の構文が必要です。                                                          |

## テーマ エディター フィールドのハイライト機能

テーマエディターでプレビューハイライト機能を使用すると、コンテンツ作成者が、どのフィールドがどのページ要素を制御しているかを理解するのに役立ちます。プレビューハイライト機能は、テーマフィールドをそのフィールドの影響を受けるCSSセレクターにマッピングすることによって機能します。テーマエディターでフィールドにカーソルを合わせると、そのフィールドがマッピングされている要素がボックスで囲んで表示されるという仕組みです。

テーマフィールドのプレビューハイライト機能を構成するには、テーマのルートディレクトリー内に、テーマフィールドとCSSセレクターのリストとのマッピングを指定するための`editor-preview.json`ファイルを追加します。このファイルで、関連するCSSセレクターが含まれる、ハイライト表示する対象のスタイルフィールドごとに、次の形式を使用して配列を含めます。

```json theme={null}
// editor-preview.json
{
  "selectors": {
    "theme.settings.path.1": [ <CSS selectors> ],
    "theme.settings.path.2": [ <CSS selectors> ],
  }
}
```

例えば、以下のコードは、プライマリー フォント フィールドによって制御されるページ要素をハイライト表示します。完全な例については、デフォルトのGrowthテーマの`editor-preview.json`ファイルでご確認ください。

```json theme={null}
// editor-preview.json
{
  "selectors": {
    "fonts.primary": [
      "button, .button, .hs-button",
      "form input[type='submit'], form .hs-button",
      ".error-page:before",
      "p",
      "blockquote > footer",
      "form td.is-today .pika-button",
      "form .is-selected .pika-button",
      "th, td",
      ".blog-listing__post-tag",
      ".blog-listing__post-author-name, .blog-post__author-name",
      ".pagination__link-icon svg",
      ".tabs__tab",
      "a",
      ".button.button--simple",
      ".pagination__link .pagination__link-icon svg",
      ".card--dark",
      ".card--light",
      ".card--light summary, .card--light p, .card--light h1, .card--light h2, .card--light h3, .card--light h4, .card--light h5, .card--light h6, .card--light a:not(.button), .card--light span, .card--light div, .card--light li, .card--light blockquote",
      ".card--light .accordion__summary:before",
      "tfoot th, tfoot td",
      ".header__language-switcher-current-label > span",
      ".header__language-switcher-child-toggle svg",
      ".header__language-switcher .lang_list_class a:not(.button)",
      ".header__menu-link",
      ".header__menu-item--depth-1 > .header__menu-link:not(.button)",
      ".header__menu-item--depth-1 .header__menu-child-toggle svg",
      ".header__menu-toggle svg",
      ".header__language-switcher .header__language-switcher-current-label > span",
      ".header p, .header h1, .header h2, .header h3, .header h4, .header h5, .header h6, .header a:not(.button), .header span, .header li, .header blockquote, .header .tabs__tab, .header .tabs__tab, .header .tabs__tab, .header .tabs__tab",
      ".footer .hs-menu-wrapper a",
      ".footer h1, .footer h2, .footer h3, .footer h4, .footer h5, .footer h6, .footer p, .footer a:not(.button), .footer span, .footer div, .footer li, .footer blockquote, .footer .tabs__tab, .footer .tabs__tab, .footer .tabs__tab, .footer .tabs__tab",
      ".footer hr",
      "form label",
      "#email-prefs-form, #email-prefs-form h1, #email-prefs-form h2",
      "form legend",
      "form input[type='text'], form input[type='email'], form input[type='password'], form input[type='tel'], form input[type='number'], form input[type='search'], form select, form textarea",
      ".backup-unsubscribe input[type='email']",
      "form .legal-consent-container, form .legal-consent-container .hs-richtext, form .legal-consent-container .hs-richtext p",
      "form .hs-richtext, form .hs-richtext *, form .hs-richtext p, form .hs-richtext h1, form .hs-richtext h2, form .hs-richtext h3, form .hs-richtext h4, form .hs-richtext h5, form .hs-richtext h6",
      "button, button, button, .button, .button, .button, .hs-button, .hs-button, .hs-button",
      "button, .button, .hs-button",
      ".button.button--secondary, .button.button--secondary, .button.button--secondary",
      ".button.button--secondary",
      ".header__menu-item--depth-1 > .header__menu-link, .header__menu-item--depth-1 > .header__menu-link",
      ".header__menu-item--depth-1 > .header__menu-link",
      ".header__menu-submenu .header__menu-link, .header__menu-submenu .header__menu-link",
      ".header__language-switcher .lang_list_class a, .header__language-switcher .lang_list_class a",
      ".header__menu-submenu .header__menu-link:not(.button)",
      ".footer .hs-menu-wrapper a, .footer .hs-menu-wrapper a",
      ".footer .hs-menu-wrapper a",
      "form .hs-richtext a",
      ".header__menu-item--depth-1 > .header__menu-link--active-link:not(.button)",
      ".footer .hs-menu-wrapper .active > a"
    ]
  }
}
```

<Frame>
  <img src="https://www.hubspot.jp/hubfs/Knowledge_Base_2023/growth-theme-hover.png" alt="Growthテーマ-hover" />
</Frame>

このファイルを作成するには、まず、次の[CLIコマンド](/developer-tooling/local-development/hubspot-cli/reference#generate-theme-field-selectors-for-in-app-highlighting)を実行してファイルを生成します。ファイルの生成中にスクリプトが実行されて、初期フィールド セレクター マッピングが設定されます。

```shell theme={null}
hs theme generate-selectors <theme-directory-path>
```

| パラメーター                 | 説明              |
| ---------------------- | --------------- |
| `theme-directory-path` | テーマディレクトリーへのパス。 |

このコマンドを実行した後、`editor-preview.json`ファイルを確認し、フィールドとセレクターが適切にマッピングされるように調整する必要があります。[Generate-selectors](/developer-tooling/local-development/hubspot-cli/reference#generate-theme-field-selectors-for-in-app-highlighting)コマンドでは、どのフィールドがどのセレクターに影響するかについて基本的な推測が行われるだけなので、テーマがどのように作成されているかに基づいて修正する必要があります。例えばこのコマンドでは、モジュールがスタイル設定をオーバーライドしていたり、マクロが使用されたりしていても検出できません。

設定されているマッピングをテストするには、テーマをアカウントにアップロードし、そのアカウント内でテーマエディターを表示します（［設定］＞［ウェブサイト］＞［テーマ］＞［テーマを表示］）。
