> ## 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.

# HubLフィルター

> HubSpotのCMS開発者向けのHubLフィルターの一覧と例。

フィルターはHubLの最終出力に影響を与えます。さまざまなHubL文と式にフィルターを適用することで、サーバーから出力されるテンプレートマークアップを変更できます。

フィルターの基本構文は`|filtername`です。フィルターは文または式のすぐ後に、区切り記号で囲んで追加します。パラメーターを括弧内に追加指定できるフィルターもあります。文字列、数値、およびブール値のパラメーターを使用するフィルターの基本構文は、`|filtername("stringParameter", 10, true)`です。文字列パラメーターについては、引用符で囲む必要があることに注意してください。また、HubLフィルターにはエイリアスが存在し、それをプライマリーフィルターと同じ目的に使用できます。

以下にて、サポートされる全てのHubLフィルターを示します。

<Warning>
  ### 注:

  CMS Hub上のページやブログ記事では、コンタクトトークンや会社トークンなどの[パーソナライズトークン](https://knowledge.hubspot.com/ja/website-pages/personalize-your-content)にHubLフィルターを適用できますが、Eメールでは適用<u>できません</u>。
</Warning>

## abs

数値の絶対値を取得します。このフィルターを使用すると、常に正の数値が得られます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_number = -53 %}
  {{ my_number|abs }}
  ```

  ```text レンダリングされる出力.txt theme={null}
  53
  ```
</CodeGroup>

## add

1つの数値を別の数値に加算します。このフィルターは[+演算子](/cms/reference/hubl/operators-and-expression-tests#math)と同じように機能します。括弧内のパラメーターは、最初の数値に合わせる加算値です。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_num = 40 %}
  {{ my_num|add(13) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  53
  ```
</CodeGroup>

## attr

ディクショナリー（辞書型）の属性をレンダリングします。このフィルターの機能は、`content.absolute_url`など、ディクショナリーに含まれる変数を出力する機能と同等です。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content|attr("absolute_url") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  https://developers.hubspot.com/docs/cms/hubl/filters
  ```
</CodeGroup>

| パラメーター           | 説明               |
| ---------------- | ---------------- |
| `attribute_name` | どの属性を出力するかを指定します |

## batch

1つのシーケンス内の複数項目をグループ化します。

以下の例では、フルーツの種類からなるシーケンスが変数に格納されています。`batch`フィルターは、シーケンスを反復処理するループに適用されます。入れ子ループが3回実行され、行ごとに3種類のフルーツを出力した後、外側のループが再び実行されます。フルーツが5種類しかないので、最終的な出力では最後の項目が`&nbsp;`（2番目のパラメーター）に置き換えられる点にご注目ください。

<CodeGroup>
  ```html example.html theme={null}
  {% set rows = ["apples", "oranges", "pears", "grapes", "blueberries"] %}

  <table>
  {% for row in rows|batch(3, " ") %}
  <tr>
  {% for column in row %}
  <td>{{ column }}</td>
  {% endfor %}
  </tr>
  {% endfor %}
  </table>
  ```

  ```html example.html theme={null}
  <table>
  <tbody>
  <tr>
  <td>apples</td>
  <td>oranges</td>
  <td>pears</td>
  </tr>
  <tr>
  <td>grapes</td>
  <td>blueberries</td>
  <td>&nbsp;</td>
  </tr>
  </tbody>
  </table>
  ```
</CodeGroup>

| パラメーター      | タイプ | 説明                       |
| ----------- | --- | ------------------------ |
| `linecount` | 数値  | バッチに含める項目の数。             |
| `fill_with` | 文字列 | 項目の欠落がある場合に何で埋めるかを指定します。 |

## between\_times

指定された時間単位を使用して、2つの日時オブジェクト間の差異を計算します。

<Warning>
  ### 注:

  このフィルターは、日付を返す変数で<u>のみ</u>使用してください。2024年9月30日以降、このフィルターはnull値が渡された場合に現在の日付を返さなくなります。この日付を過ぎると、フィルター内のnull値は2024年9月30日を返します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set begin = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
  {% set end = "2018-07-20T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
  {{ begin|between_times(end, "days") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  6
  ```
</CodeGroup>

| パラメーター     | タイプ      | 説明                                                                                                                                                     |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `end`      | 日時オブジェクト | 終了日時オブジェクト。                                                                                                                                            |
| `timeunit` | 文字列      | 有効な時間単位は、`nanos`、`micros`、`millis`、`seconds`、`minutes`、`hours`、`half_days`、`days`、`weeks`、`months`、`years`、`decades`、`centuries`、`millennia`、`eras`です。 |

## bool

テキスト文字列の値をブール値に変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% if "true"|bool == true %}hello world{% endif %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  hello world
  ```
</CodeGroup>

## capitalize

変数値の最初の文字を大文字にします。最初の文字が大文字になり、その他の文字は全て小文字になります。スペースまたはハイフンで区切られている後続の単語について、最初の文字は大文字になりません。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set sentence = "the first letter of a sentence should always be capitalized." %}
  {{ sentence|capitalize }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  The first letter of a sentence should always be capitalized.
  ```
</CodeGroup>

## center

空白を使用して、指定されたフィールドの長さ内でテキストを中央に配置します。HubSpotのHTMLコンパイラーは自動的に空白を除去するので、このフィルターは推奨されず、特に役立つわけでもありませんが、包括的な説明のためにここで説明しています。

以下の例では、空白が除去されないようにpreタグ内の変数にこのフィルターを適用しています。

<CodeGroup>
  ```html example.html theme={null}
  <pre>
  {% set var = "string to center" %}
  before{{ var|center(80) }}after
  </pre>
  ```

  ```html example.html theme={null}
  <pre>
  before                                string to center                                after
  </pre>
  ```
</CodeGroup>

| パラメーター  | タイプ | 説明                         |
| ------- | --- | -------------------------- |
| `width` | 数値  | テキストを中央揃えするための空白の長さを指定します。 |

## convert\_rgb

HEX値をRGB文字列に変換します。色変数をRGBに変換して、RGBA CSS宣言で使用する必要がある場合に便利です。以下の例では、色モジュールによって設定された値がRGB値に変換され、RGBA CSS宣言で使用されます。

<CodeGroup>
  ```html example.html theme={null}
  {% set my_color = "#FFFFFF" %}
  {{ my_color|convert_rgb }}
  {% set my_color2="#000000" %}
  <div style="background: rgba({{ my_color2|convert_rgb }}, .5)"></div>
  ```

  ```html example.html theme={null}
  255, 255, 255

  <div style="background: rgba(0, 0, 0, .5)"></div>
  ```
</CodeGroup>

## cut

値から文字列を除去します。このフィルターを使用すると、一致する特定の部分文字列を切り取ることができます。パラメーターには、削除対象となる部分文字列を指定します。以下の例では、スペースと単語「world」が元の変数値から除去されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_string = "Hello world." %}
  {{ my_string|cut(" world") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Hello.
  ```
</CodeGroup>

| パラメーター              | タイプ | 説明            |
| ------------------- | --- | ------------- |
| `characters_to_cut` | 文字列 | 削除対象となる部分文字列。 |

## datetimeformat（非推奨）

<Warning>
  ### 注:

  このフィルターは[非推奨](/cms/versions-deprecations/deprecated/hubl/filters-functions#datetimeformat-function)になりました。代わりに、より標準化された構文を使用する[format\_datetime](#format-datetime)フィルターを使用してください。
</Warning>

## default

値が未定義の場合に、最初のパラメーターを返します。それ以外の場合、変数の値が出力されます。Falseと評価される変数でdefaultを使用するには、2番目のパラメーターを`true`に設定する必要があります。

以下の1つ目の例では、変数が未定義の場合にメッセージが出力されます。2つ目の例では、未定義ではない空の文字列にフィルターを適用していますが、2番目のパラメーターが原因でメッセージが出力されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ my_variable|default("my_variable is not defined") }}
  {{ ""|default("the string was empty", true) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  my_variable is not defined the string was empty
  ```
</CodeGroup>

| パラメーター          | タイプ  | 説明                                        |
| --------------- | ---- | ----------------------------------------- |
| `default_value` | 文字列  | 変数が未定義の場合に返される値。変数が定義されている場合は、変数の値が返されます。 |
| `truthy`        | ブール値 | `false`と評価される変数で使用するには、`true`に設定します。      |

## dictsort

ディクショナリー（辞書型）を並べ替えて「キー、値」のペアを生成します。ディクショナリーはデフォルトでは並べ替えられませんが、キーまたは値を基準に並べ替えてディクショナリーを出力できます。最初のパラメーターは、並べ替えで大文字と小文字を区別するかどうかを決定するブール値です。2番目のパラメーターは、キーと値のどちらを基準にディクショナリーを並べ替えるかを決定します。以下の例では、コンタクトについて確認済みの詳細情報を全て含む、並べ替えられたコンタクトディクショナリーを出力します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% for item in contact|dictsort(false, "value") %}
  {{item}}
  {% endfor %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  A sorted contact dictionary
  ```
</CodeGroup>

| パラメーター           | タイプ                  | 説明                                   |
| ---------------- | -------------------- | ------------------------------------ |
| `case_sensitive` | ブール値                 | 並べ替えの際に大文字と小文字を区別するかどうかを指定します。       |
| `sort_by`        | `"key"` \| `"value"` | `key`または`value`のどちらを基準に並べ替えるかを指定します。 |

## difference

このフィルターは、2つのセットまたはリストの差異を返します。フィルターから返されるリストには、最初のリストに含まれ、2番目には含まれない一意の要素が全て格納されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ [1, 2, 3]|difference([2, 3, 4, 5]) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [1]
  ```
</CodeGroup>

| パラメーター | タイプ | 説明                             |
| ------ | --- | ------------------------------ |
| `list` | 配列  | 最初のリストとの差異を見つけるために比較する2番目のリスト。 |

## divide

現在の値を除数で割ります。渡すパラメーターは除数です。このフィルターは、/演算子の代わりになります。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set numerator = 106 %}
  {{ numerator|divide(2) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  53
  ```
</CodeGroup>

| パラメーター    | タイプ | 説明            |
| --------- | --- | ------------- |
| `divisor` | 数値  | 変数を除算するための数値。 |

## divisible

Divisibleフィルターは、`divisibleby`式評価の代わりになります。値を特定の数で割り切れる場合、trueと評価されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set num = 10 %}
  {% if num|divisible(2) %}
  The number is divisible by 2
  {% endif %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  The number is divisible by 2
  ```
</CodeGroup>

| パラメーター    | タイプ | 説明                         |
| --------- | --- | -------------------------- |
| `divisor` | 数値  | 値を割り切れるかどうかを評価するために使用する数値。 |

## escape\_html

HTML入力の内容をエスケープします。文字列を受け入れ、`&`、`<`、`>`、`‘`、`”`、および`escape_jinjava`文字をHTMLで安全に使用できるシーケンスに変換します。HTMLで使用されているものの、HTMLを許可しないHubL変数には、このフィルターを使用します。

<CodeGroup>
  ```html example.html theme={null}
  {% set escape_string = "<div>This markup is printed as text</div>" %}
  {{ escape_string|escape_html }}
  ```

  ```html example.html theme={null}
  <div>This markup is printed as text</div>
  ```
</CodeGroup>

## escape\_attr

HTML属性入力の内容をエスケープします。文字列を受け入れ、`&`、`<`、`‘`、`”`、および`escape_jinjava`文字をHTMLで安全に使用できるシーケンスに変換します。このフィルターは、HTML属性に追加されるHubL変数に使用します。

`href`など、URLを受け入れる属性の値をエスケープする場合は、代わりに`escape_url`フィルターを使用してください。

<CodeGroup>
  ```html example.html theme={null}
  {% set escape_string = "This <br> markup is printed as text" %}
  <img src="test.com/imageurl" alt="{{escape_string|escape_attr}}">
  ```

  ```html example.html theme={null}
  <img src="test.com/imageurl" alt="This <br> markup is printed as text" />
  ```
</CodeGroup>

## escape\_jinjava

文字列内の`{`および`}`文字を、Jinjavaで安全に使用できるシーケンスに変換します。このような文字が含まれる可能性のあるテキストをJinjavaで表示する際にこのフィルターを使用します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "{{This markup is printed as text}}" %}
  {{ escape_string|escape_jinjava }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  {{This markup is printed as text}}
  ```
</CodeGroup>

## escape\_js

JavaScript変数宣言に文字列を安全に挿入できるように、（`escape_jinjava`を含む）文字列をエスケープ処理します。このフィルターは、HTMLスクリプト要素内で使用されるHubL変数に使用します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "\tThey said 'This string can safely be inserted into JavaScript.'" %}
  {{ escape_string|escape_js }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  \tThey said \x27This string can safely be inserted into JavaScript.\x27
  ```
</CodeGroup>

## escape\_url

URL入力の内容をエスケープし、指定されたプロトコルを実行し、無効で危険な文字を削除し、HTMLエンティティーをエンコードします。URLが有効な場合は空の値を返します。このフィルターは、有効なURLである必要があるHTML属性内で使用されるHubL変数に使用します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "http://example.com/with space/<html>" %}
  <a href="https://developers.hubspot.jp/docs{{ escape_string|escape_url }}"></a>
  ```

  ```text 出力のレンダリング.txt theme={null}
  <a href="http://example.com/with%20space/%3Chtml%3E"></a>
  ```
</CodeGroup>

## escapejson

文字列をJSON値として使用できるように、文字列をエスケープ処理します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "<script>alert('oh no!')</script>" %}
  {% require_js position="head" %}
  <script data-search_input-config="config_{{ name }}" type="application/json">
  {
  "autosuggest_results_message": "{{ escape_string|escapejson }}"
  }
  </script>
  {% end_require_js %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  <script
  data-search_input-config="config_widget_1234567"
  type="application/json"
  >
  {
  "autosuggest_results_message": "<script>alert('oh no!')<\/script>"
  }
  </script>
  ```
</CodeGroup>

## filesizeformat

数値を判読可能なファイルサイズ（13 kB、4.1 MB、102 Bytesなど）に変更します。デフォルトでは10進プレフィックス（MBやGBなど）が使用されますが、Mebi（MiB）やGibi（GiB）などのバイナリープレフィックスを使用するには、`binary`パラメーターを`true`に設定します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set bytes = 10000 %}
  {{ bytes|filesizeformat(binary=true) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  9.8 KiB
  ```
</CodeGroup>

| パラメーター   | タイプ  | 説明                                                      |
| -------- | ---- | ------------------------------------------------------- |
| `binary` | ブール値 | `true`に設定すると、Mebi（MiB）やGibi（GiB）などのバイナリープレフィックスが使用されます。 |

## first

シーケンス内の最初の項目を返します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_sequence = ["Item 1", "Item 2", "Item 3"] %}
  {{ my_sequence|first }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Item 1
  ```
</CodeGroup>

## float

値を浮動小数点値に変換します。正常に変換できない場合は`0.0`を返します。このデフォルトの動作は、最初のパラメーターを使用することで変更できます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_text="25" %}
  {{ my_text|float + 17 }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  42.0
  ```
</CodeGroup>

| パラメーター    | タイプ | 説明                  |
| --------- | --- | ------------------- |
| `default` | 数値  | 正常に変換できない場合に返される整数。 |

## forceescape

厳密なHTMLエスケープを実行します。HubSpotの環境では二重にエスケープを行うケースがないため、基本的にはescapeフィルターと同じ動作をします。

<CodeGroup>
  ```html example.html theme={null}
  {% set escape_string = "<div>This markup is printed as text</div>" %}
  {{ escape_string|forceescape }}
  ```

  ```html example.html theme={null}
  <div>This markup is printed as text</div>
  ```
</CodeGroup>

## format

Python文字列の書式設定をオブジェクトに適用します。`%s`を別の変数に置換できます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ "Hi %s %s"|format(contact.firstname, contact.lastname) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Hi Monty Python
  ```
</CodeGroup>

## format\_currency（非推奨）

<Warning>
  ### 注:

  このフィルターは[非推奨](/cms/versions-deprecations/deprecated/hubl/filters-functions)になりました。代わりに、[format\_currency\_value](#format-currency-value)フィルターを使用してください。
</Warning>

## format\_currency\_value

パラメーターとして渡されるポータルのデフォルトの通貨とロケールに基づき、特定の数値の書式を通貨として設定します。非推奨の[format\_currencyフィルター](/cms/versions-deprecations/deprecated/hubl/filters-functions#format-currency)を置き換えるものです。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ 100 | format_currency_value(locale='en-GB', currency='EUR', maxDecimalDigits=6, minDecimalDigits=1) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  €100.0
  ```
</CodeGroup>

| パラメーター             | タイプ | 説明                                                                                                                                                                                             |
| ------------------ | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `locale`           | 文字列 | [Javaローカル言語タグ](https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html)（英語）。デフォルトはページの`locale.Format : ISO639LanguageCodeInLowercase-ISO3166CountryCodeInUppercase`です。 |
| `currency`         | 文字列 | 通貨の[英字のISO 4217コード](https://en.wikipedia.org/wiki/ISO_4217)。デフォルトは、ポータルのデフォルトの通貨です。数値コードは使用できません。                                                                                              |
| `minDecimalDigits` | 数値  | 出力に含める小数桁数の最小値。デフォルトで、通貨のデフォルトの小数桁数に設定されます。                                                                                                                                                    |
| `maxDecimalDigits` | 数値  | 出力に含める小数桁数の最大値。デフォルトで、通貨のデフォルトの小数桁数に設定されます。                                                                                                                                                    |

## format\_date

日付オブジェクトの日付コンポーネントを書式設定します。

<Warning>
  ### 注:

  このフィルターは、日付を返す変数で<u>のみ</u>使用してください。2024年9月30日以降、このフィルターはnull値が渡された場合に現在の日付を返さなくなります。この日付を過ぎると、フィルター内のnull値は2024年9月30日を返します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content.publish_date | format_date('long') }}
  {{ content.publish_date | format_date('yyyy.MMMM.dd') }}
  {{ content.publish_date | format_date('medium', 'America/New_York', 'de-DE') }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  November 28, 2022 02022.November.28 28.11.2022
  ```
</CodeGroup>

| パラメーター     | タイプ                                                         | 説明                                                                                                                     |
| ---------- | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| カスタムパターン | 使用する形式。[Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns)（英語）に従ったカスタムパターンを指定できます。   |
| `timeZone` | 文字列                                                         | [IANA TZDB形式](https://data.iana.org/time-zones/tzdb/)（英語）で出力される日付のタイムゾーン。                                              |
| `locale`   | 文字列                                                         | ロケール対応の形式に使用するロケール。[サポートされているロケールの一覧](https://www.oracle.com/java/technologies/javase/java8locales.html)（英語）を参照してください。 |

## format\_datetime

日付オブジェクトの日付と時刻のコンポーネント両方を書式設定します。このフィルターは、非推奨になった[datetimeformat](/cms/versions-deprecations/deprecated/hubl/filters-functions#datetimeformat-filter)フィルターの後続となるものです。デフォルトでは、UTC-00:00のタイムゾーンの日時を返します。

<Warning>
  ### 注:

  このフィルターは、日付を返す変数で<u>のみ</u>使用してください。2024年9月30日以降、このフィルターはnull値が渡された場合に現在の日付を返さなくなります。この日付を過ぎると、フィルター内のnull値は2024年9月30日を返します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content.publish_date | format_datetime('medium', 'America/New_York', 'de-DE') }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  12/31/69 7:00 PM
  ```
</CodeGroup>

| パラメーター     | タイプ                                                         | 説明                                                                                                                                                                                                                            |
| ---------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| カスタムパターン | 使用する形式。[Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns)に従うカスタムパターンを指定できます。`long`または`full`を使用する場合、タイムスタンプにはZが含まれ、オフセットがゼロであるUTC時間（つまり`2:23:00 PM Z`）を示します。Z指定子を削除するには`timeZone`を指定してください。 |
| `timeZone` | 文字列                                                         | [IANA TZDB形式](https://data.iana.org/time-zones/tzdb/)（英語）で出力される日付のタイムゾーン。デフォルトではUTC時間を返します。                                                                                                                                   |
| `locale`   | 文字列                                                         | ロケール対応の形式に使用するロケール。[サポートされているロケールの一覧](https://www.oracle.com/java/technologies/javase/java8locales.html)（英語）を参照してください。                                                                                                        |

## format\_number

指定されたロケールに基づいて、特定の数値の書式を設定します。小数点以下の最大精度を設定する2番目のパラメーターを含みます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ 1000|format_number('en-US') }}
  {{ 1000.333|format_number('fr') }}
  {{ 1000.333|format_number('en-US', 2) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  1,000
  1 000,333
  1,000.33
  ```
</CodeGroup>

| パラメーター             | タイプ | 説明                                                                                                                |
| ------------------ | --- | ----------------------------------------------------------------------------------------------------------------- |
| `locale`           | 文字列 | 書式設定に使用するロケール。[サポートされているロケールの一覧](https://www.oracle.com/java/technologies/javase/java8locales.html)（英語）を参照してください。 |
| `maxDecimalDigits` | 数値  | 出力に含める小数桁数の最大値。デフォルトでは、入力値の小数桁数を使用します。                                                                            |

## format\_time

日付オブジェクトの時刻コンポーネントを書式設定します。

<Warning>
  ### 注:

  このフィルターは、日付を返す変数で<u>のみ</u>使用してください。2024年9月30日以降、このフィルターはnull値が渡された場合に現在の日付を返さなくなります。この日付を過ぎると、フィルター内のnull値は2024年9月30日を返します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content.updated | format_time('long') }}
  {{ content.updated | format_time('hh:mm a') }}
  {{ content.updated | format_time('medium', 'America/New_York', 'de-DE') }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  3:25:06 PM Z 03:25 PM 10:25:44
  ```
</CodeGroup>

| パラメーター     | タイプ                                                         | 説明                                                                                                                                                                                                                            |
| ---------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| カスタムパターン | 使用する形式。[Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns)に従うカスタムパターンを指定できます。`long`または`full`を使用する場合、タイムスタンプにはZが含まれ、オフセットがゼロであるUTC時間（つまり`2:23:00 PM Z`）を示します。Z指定子を削除するには`timeZone`を指定してください。 |
| `timeZone` | 文字列                                                         | [IANA TZDB形式](https://data.iana.org/time-zones/tzdb/)（英語）で出力される日付のタイムゾーン。デフォルトではUTC時間を返します。                                                                                                                                   |
| `locale`   | 文字列                                                         | ロケール対応の形式に使用するロケール。[サポートされているロケールの一覧](https://www.oracle.com/java/technologies/javase/java8locales.html)（英語）を参照してください。                                                                                                        |

## fromjson

JSON文字列をオブジェクトに変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set obj ='{ "name":"Brian","role":"Owner" }' %}
  {{ obj|fromjson }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  {role=Owner, name=Brian}
  ```
</CodeGroup>

## geo\_distance

地上の2地点間の楕円2D距離を計算します。

<CodeGroup>
  ```text hubl.txt theme={null}
  <!-- in the example below
  the HubDB Location =
  42.3667, -71.1060 (Cambridge, MA) |
  Chicago, IL = 37.3435, -122.0344 -->
  {{ row.location | geo_distance(37.3435, -122.0344, "mi") }} MI
  ```

  ```text 出力のレンダリング.txt theme={null}
  861.1655563461395 MI
  ```
</CodeGroup>

## groupby

共通の属性を基準に、一連のオブジェクトをグループ化します。パラメーターで、グループ化の基準となる共通属性を設定します。

<CodeGroup>
  ```html example.html theme={null}
  <ul>
  {% for group in contents|groupby("blog_post_author") %}
  <li>{{ group.grouper }}
  <ul>
  {% for content in group.list %}
  <li>{{ content.name }}</li>
  {% endfor %}
  </ul>
  </li>
  {% endfor %}
  </ul>
  ```

  ```text 出力のレンダリング.txt theme={null}
  <ul>
  <li>
  Blog author 1
  <ul>
  <li>Post by Blog author 1</li>
  <li></li>
  <li>Post by Blog author 1</li>
  <li></li>
  <li>Post by Blog author 1</li>
  <li></li>
  </ul>
  </li>
  <li>
  Blog author 2
  <ul>
  <li>Post by Blog author 2</li>
  <li></li>
  <li>Post by Blog author 2</li>
  <li></li>
  <li>Post by Blog author 2</li>
  <li></li>
  </ul>
  </li>
  <li>
  Blog author 3
  <ul>
  <li>Post by Blog author 3</li>
  <li></li>
  <li>Post by Blog author 3</li>
  <li></li>
  <li>Post by Blog author 3</li>
  <li></li>
  </ul>
  </li>
  </ul>
  ```
</CodeGroup>

| パラメーター      | 説明             |
| ----------- | -------------- |
| `attribute` | グループ化の基準となる属性。 |

## indent

空白を使用して、指定されたフィールドの長さ内でテキストをインデントします。HubSpotのHTMLコンパイラーは自動的に空白を除去するので、このフィルターは推奨されず、特に役立つわけでもありませんが、包括的な説明のためにここで説明しています。以下の例では、空白が除去されないように`<pre>`タグ内の変数に`indent`フィルターを適用しています。最初のパラメーターは空白の幅を制御し、2番目のブール値は最初の行をインデントするかどうかを切り替えます。

<CodeGroup>
  ```html example.html theme={null}
  <pre>
  {% set var = "string to indent" %}
  {{ var|indent(2, true) }}
  </pre>
  ```

  ```text 出力のレンダリング.txt theme={null}
  string to indent
  ```
</CodeGroup>

| パラメーター         | タイプ  | 説明                           |
| -------------- | ---- | ---------------------------- |
| `width`        | 数値   | 適用される空白の幅。                   |
| `indent-first` | ブール値 | `true`に設定すると、最初の行がインデントされます。 |

## int

値を整数に変換します。正常に変換できない場合は`0`を返します。このデフォルトの動作は、最初のパラメーターを使用することで変更できます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set string="25" %}
  {{ string|int + 17 }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  42
  ```
</CodeGroup>

| パラメーター    | タイプ | 説明                  |
| --------- | --- | ------------------- |
| `default` | 数値  | 正常に変換できない場合に返される整数。 |

## intersect

2つのセットまたはリストの共通部分を返します。フィルターから返されるリストには、両方のリストに含まれる一意の要素が全て格納されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ [1, 2, 3]|intersect([2, 3, 4, 5]) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [2, 3]
  ```
</CodeGroup>

| パラメーター | タイプ | 説明                                |
| ------ | --- | --------------------------------- |
| `list` | 整列  | 最初のリストとの共通部分を見つけるために比較される2番目のリスト。 |

## ipaddr

値が有効なIPv4またはIPv6アドレスの場合には、`true`と評価されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set ip = "1.0.0.1" %}
  {% if ip|ipaddr %}
  The string is a valid IP address
  {% endif %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  The string is a valid IP address
  ```
</CodeGroup>

## join

シーケンスの文字列を連結した1つの文字列を返します。要素間はデフォルトでは空文字列で区切られますが、任意指定のパラメーターを使って区切り文字を定義できます。2番目のパラメーターを使用すると、結合する属性を指定できます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_list = [1, 2, 3] %}
  {% set sep = "---" %}
  {{ my_list|join }}
  {{ my_list|join("|") }}
  {{ my_list|join(sep) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  123 1|2|3 1---2---3
  ```
</CodeGroup>

| パラメーター      | タイプ    | 説明                |
| ----------- | ------ | ----------------- |
| `delimiter` | 文字列    | 文字列の連結に使用する区切り文字。 |
| `attribute` | HubL変数 | オブジェクト内で結合する値の属性。 |

## last

シーケンスの最後の項目を返します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_sequence = ["Item 1", "Item 2", "Item 3"] %}
  {% my_sequence|last %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Item 3
  ```
</CodeGroup>

## length

シーケンスまたはマッピング内の項目数を返します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set services = ["Web design", "SEO", "Inbound Marketing", "PPC"] %}
  {{ services|length }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  4
  ```
</CodeGroup>

## list

値を変換して1つのリストにします。文字列は、角括弧シーケンスの区切り文字`[ ]`で囲まれていない限り、別々の文字として返されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set one = 1 %}
  {% set two = 2 %}
  {% set three = "three" %}
  {% set four = ["four"] %}
  {% set list_num = one|list + two|list + three|list + four|list %}
  {{ list_num }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [1, 2, t, h, r, e, e, four]
  ```
</CodeGroup>

## log

数値の自然対数を計算します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ 10|log }}
  {{ 65536|log(2) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  2.302585092994046 16.0
  ```
</CodeGroup>

| パラメーター | タイプ | 説明           |
| ------ | --- | ------------ |
| `base` | 数値  | 対数計算に使用する基数。 |

## lower

値に含まれる全ての文字を小文字に変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set text="Text to MAKE LowercaSe" %}
  {{ text|lower }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  text to make lowercase
  ```
</CodeGroup>

## map

オブジェクトのシーケンスにフィルターを適用するか、属性を検索します。オブジェクトリストを扱うとき、その中の特定の値だけに対象を絞り込むには、これが便利です。

基本的な使用法は、属性に対するマッピングです。例えば、ディクショナリーの特定の属性に特定の値が存在するかどうかを検査する条件付きロジックを使用する場合です。または、フィルター名と引数を渡してフィルターを起動することもできます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {# Usage 1 #}
  Apply a filter to a sequence:
  {% set seq = ["item1", "item2", "item3"] %}
  {{ seq|map("upper") }}

  {# Usage 2 #}
  Look up an attribute:
  {{ content|map("currentState")}}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Apply a filter to a sequence: [ITEM1, ITEM2, ITEM3]
  Look up an attribute: [DRAFT]
  ```
</CodeGroup>

| パラメーター   | タイプ | 説明                      |
| -------- | --- | ----------------------- |
| `filter` | 文字列 | オブジェクトのシーケンスに適用するフィルター。 |

## md5

特定のオブジェクトの[md5ハッシュ](https://ja.wikipedia.org/wiki/MD5)を計算します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content.absolute_url|md5 }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  923adb4ce05a4c6342c04c80be88d15e
  ```
</CodeGroup>

## minus\_time

日時オブジェクトで一定の時間を差し引きます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
  {{ date }}
  {{ date|minus_time(2, "months") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  2018-07-14 14:31:30 2018-05-14 14:31:30
  ```
</CodeGroup>

| パラメーター     | タイプ | 説明                                                                                                                                                     |
| ---------- | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `diff`     | 数値  | 差し引く数量。                                                                                                                                                |
| `timeunit` | 文字列 | 有効な時間単位は、`nanos`、`micros`、`millis`、`seconds`、`minutes`、`hours`、`half_days`、`days`、`weeks`、`months`、`years`、`decades`、`centuries`、`millennia`、`eras`です。 |

## multiply

1つの値を数値で乗算します。[\*演算子](/cms/reference/hubl/operators-and-expression-tests)と同じ機能です。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set n = 20 %}
  {{ n|multiply(3) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  60
  ```
</CodeGroup>

## plus\_time

日時オブジェクトに一定の時間を加えます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
  {{ date }}
  {{ date|plus_time(5, "days") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  2018-07-14 14:31:30 2018-07-19 14:31:30
  ```
</CodeGroup>

| パラメーター     | タイプ | 説明                                                                                                                                                     |
| ---------- | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `diff`     | 数値  | 差し引く数量。                                                                                                                                                |
| `timeunit` | 文字列 | 有効な時間単位は、`nanos`、`micros`、`millis`、`seconds`、`minutes`、`hours`、`half_days`、`days`、`weeks`、`months`、`years`、`decades`、`centuries`、`millennia`、`eras`です。 |

## pprint

変数をpprintします。変数の型など、デバッグに役立つ情報を出力します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set this_var ="Variable that I want to debug" %}
  {{ this_var|pprint }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  (String: Variable that I want to debug)
  ```
</CodeGroup>

## random

シーケンスからランダムな1つの項目を返します。

<Warning>
  ### 注:

  このフィルターを使用すると、ページコンテンツの更新時ではなく、定期的にページの[プリレンダリング](/cms/best-practices/testing-staging-performance/prerendering)が実行されます。つまり、フィルタリングされたコンテンツは、ページの再読み込みのたびに更新されるわけでは<u>ありません</u>。

  これは、ブログ記事のランダムなリストの表示など、特定のタイプのコンテンツでは特に問題ではありません。ただし、ページを読み込むたびにコンテンツをランダムに変更する必要がある場合には、代わりにJavaScriptを使用してコンテンツをクライアント側でランダム化する必要があります。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {% for content in contents|random %}
  <div class="post-item">Post item markup</div>
  {% endfor %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  <div class="post-item">Random post</div>
  ```
</CodeGroup>

## regex\_replace

正規表現パターンを検索して、文字シーケンスで置換します。最初の引数はRE2形式の正規表現パターン、2つ目は置換文字列です。

詳しくは[RE2正規表現の構文](https://github.com/google/re2/wiki/Syntax)（英語）をご確認ください。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ "contact-us-2"|regex_replace("[^a-zA-Z]", "") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  contactus
  ```
</CodeGroup>

## reject

オブジェクトに[式による検証](/cms/reference/hubl/operators-and-expression-tests)を適用して、該当する要素を拒否することにより、オブジェクトのシーケンスをフィルタリングします。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %}
  {{ some_numbers|reject("even") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [13, 3, 5, 17]
  ```
</CodeGroup>

| パラメーター     | タイプ | 説明                                                                                        |
| ---------- | --- | ----------------------------------------------------------------------------------------- |
| `exp_text` | 文字列 | オブジェクトに適用する[式評価](/cms/reference/hubl/operators-and-expression-tests#expression-tests)の名前。 |

## rejectattr

オブジェクトの属性を検証して該当する要素を拒否することにより、オブジェクトのシーケンスをフィルタリングします。

<CodeGroup>
  ```html example.html theme={null}
  {% for content in contents|rejectattr("post_list_summary_featured_image") %}
  <div class="post-item">
  {% if content.post_list_summary_featured_image %}
  <div class="hs-featured-image-wrapper">
  <a href="https://developers.hubspot.jp/docs{{content.absolute_url}}" title="" class="hs-featured-image-link">
  <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
  </a>
  </div>
  {% endif %}
  {{ content.post_list_content|safe }}
  </div>
  {% endfor %}
  ```

  ```html example.html theme={null}
  <div class="post-item">Post with no featured image</div>
  <div class="post-item">Post with no featured image</div>
  <div class="post-item">Post with no featured image</div>
  ```
</CodeGroup>

| パラメーター           | タイプ | 説明                                                                                        |
| ---------------- | --- | ----------------------------------------------------------------------------------------- |
| `attribute_name` | 文字列 | 選択する属性を指定します。ドット表記を使用すると、ネストされた属性にアクセスできます。                                               |
| `exp_test`       | 文字列 | オブジェクトに適用する[式評価](/cms/reference/hubl/operators-and-expression-tests#expression-tests)の名前。 |

## render

HubLを含む文字列を早期にレンダリングして、出力を他のフィルターに渡すことができるようにします。

<CodeGroup>
  ```html example.html theme={null}
  {{ personalization_token("contact.lastname", "default value")|render|lower }}
  ```

  ```html example.html theme={null}
  mclaren
  ```
</CodeGroup>

## replace

部分文字列の全てのインスタンスを、新しいものに置換します。

<CodeGroup>
  ```html example.html theme={null}
  {% if topic %}
  <h3>Posts about {{ page_meta.html_title|replace("Blog | ", "") }}</h3>
  {% endif %}
  ```

  ```html example.html theme={null}
  <h3>Posts about topic name</h3>
  ```
</CodeGroup>

| パラメーター  | タイプ | 説明                       |
| ------- | --- | ------------------------ |
| `old`   | 文字列 | 置換の対象にする部分文字列。           |
| `new`   | 文字列 | 置換する文字列。                 |
| `count` | 数値  | 指定した場合、最初の出現数分のみが置換されます。 |

## reverse

オブジェクトを反転します。または、オブジェクトを逆順に反復処理するイテレーターを返します。リストを反転するには[.reverse()](/cms/reference/hubl/functions#reverse)を使用します

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}
  {% for num in nums|reverse %}
  {{ num }}
  {% endfor %}
  ```

  ```text 出力のレンダリング.txt theme={null}
  10 9 8 7 6 5 4 3 2 1
  ```
</CodeGroup>

## root

値の平方根を計算します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ 16|root }}
  {{ 625|root(4) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  4 5
  ```
</CodeGroup>

| パラメーター     | タイプ | 説明          |
| ---------- | --- | ----------- |
| `nth_root` | 数値  | 計算に使用するn乗根。 |

## round

数値を指定された精度で四捨五入します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ 52.5|round }}
  {{ 52.5|round(0, "floor") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  53 52
  ```
</CodeGroup>

| パラメーター            | タイプ                                        | 説明                                                                |
| ----------------- | ------------------------------------------ | ----------------------------------------------------------------- |
| `precision`       | 数値                                         | 端数処理の精度を指定します。                                                    |
| `rounding_method` | `'common'`（デフォルト） \| `'ceil'` \| `'floor'` | オプションには、`common`（四捨五入：デフォルト）、`ceil`（常に切り上げ）、`floor`（常に切り下げ）があります。 |

## safe

値に「safe」のマークを付けます。つまり、自動エスケープが有効になっている環境で、この変数はエスケープされません。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ content.post_list_content|safe }}
  ```

  ```html example.html theme={null}
  <p>HTML post content that is not escaped.</p>
  ```
</CodeGroup>

## sanitize\_html

リッチ テキスト コンテンツの出力用にHTML入力のコンテンツをサニタイズ処理します。文字列を受け入れ、許可されていないHTMLタグを削除します。HTMLで使用されており、安全なHTMLを許可するHubL変数に、このフィルターを使用します。

特定のタイプのHTMLタグを許可するパラメーターとして、`FORMATTING`、`BLOCKS`、`STYLES`、`LINKS`、`TABLES`、`IMAGES`を含めることができます。例えば、`sanitize_html(IMAGES)`です。

`sanitize_html`を使用すると、全てのパラメーターがフィルターに含められます。

さらに`STRIP`パラメーターを含めると、<u>全て</u>のHTMLを削除できます。また、ネストされた解釈を防ぐ目的で、全てのコンテンツが`escape_jinjava`を介して実行されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "This <br> <div>markup is <img src='test.com/image'> <span>printed</span> as text.</div>" %}
  {{ escape_string|sanitize_html("IMAGES") }}
  ```

  ```html example.html theme={null}
  This  markup is <img src="test.com/image"> printed as text.</div>
  ```
</CodeGroup>

## select

オブジェクトを検証して該当する要素だけを選ぶことにより、オブジェクトのシーケンスをフィルタリングします。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %}
  {{ some_numbers|select("even") }}
  ```

  ```html example.html theme={null}
  [10, 12, 22]
  ```
</CodeGroup>

| パラメーター     | タイプ | 説明            |
| ---------- | --- | ------------- |
| `exp_text` | 文字列 | オブジェクトを検証する式。 |

## selectattr

オブジェクトの属性を検証して該当する要素だけを選ぶことにより、オブジェクトのシーケンスをフィルタリングします。

<CodeGroup>
  ```html example.html theme={null}
  {% for content in contents|selectattr("post_list_summary_featured_image") %}
  <div class="post-item">
  {% if content.post_list_summary_featured_image %}
  <div class="hs-featured-image-wrapper">
  <a href="https://developers.hubspot.jp/docs{{content.absolute_url}}" title="" class="hs-featured-image-link">
  <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
  </a>
  </div>
  {% endif %}
  {{ content.post_list_content|safe }}
  </div>
  {% endfor %}
  ```

  ```html example.html theme={null}
  <div class="post-item">
  <div class="hs-featured-image-wrapper">
  <a
  href="http://blog.hubspot.com/marketing/how-to-get-a-job"
  title=""
  class="hs-featured-image-link"
  >
  <img
  src="//cdn2.hubspot.net/hub/53/hubfs/00-Blog-Related_Images/landing-a-job-featured-image.png?t=1431452322770&width=761"
  class="hs-featured-image"
  />
  </a>
  </div>
  Post with featured image
  </div>
  ```
</CodeGroup>

| パラメーター           | タイプ | 説明                                                                                        |
| ---------------- | --- | ----------------------------------------------------------------------------------------- |
| `attribute_name` | 文字列 | テストする属性。ドット表記を使用すると、ネストされた属性にアクセスできます。                                                    |
| `exp_test`       | 文字列 | オブジェクトに適用する[式評価](/cms/reference/hubl/operators-and-expression-tests#expression-tests)の名前。 |
| `val`            | 文字列 | テストの対象となる値。                                                                               |

## shuffle

シーケンス内の反復の順序をランダムにします。以下の例は、標準的なブログのループをシャッフルします。

<Warning>
  ### 注:

  このフィルターを使用すると、ページコンテンツの更新時ではなく、定期的にページの[プリレンダリング](/cms/best-practices/testing-staging-performance/prerendering)が実行されます。つまり、フィルタリングされたコンテンツは、ページの再読み込みのたびに更新されるわけでは<u>ありません</u>。

  これは、ブログ記事のランダムなリストの表示など、特定のタイプのコンテンツでは特に問題ではありません。ただし、ページを読み込むたびにコンテンツをランダムに変更する必要がある場合には、代わりにJavaScriptを使用してコンテンツをクライアント側でランダム化する必要があります。
</Warning>

<CodeGroup>
  ```html example.html theme={null}
  {% for content in contents|shuffle %}
  <div class="post-item">Markup of each post</div>
  {% endfor %}
  ```

  ```html example.html theme={null}
  <div class="post-item">Markup of each post 5</div>
  <div class="post-item">Markup of each post 3</div>
  <div class="post-item">Markup of each post 1</div>
  <div class="post-item">Markup of each post 2</div>
  <div class="post-item">Markup of each post 4</div>
  ```
</CodeGroup>

## slice

イテレーターをスライスして、これらの項目を含むリストの一覧を返します。最初のパラメーターにはスライスされる項目数を指定し、2番目のパラメーターには空白のスライスに埋める文字を指定します。

<CodeGroup>
  ```html example.html theme={null}
  {% set items = ["laptops", "tablets", "smartphones", "smart watches", "TVs"] %}
  <div class="columwrapper">
  {% for column in items|slice(3," ") %}
  <ul class="column-{{ loop.index }}">
  {% for item in column %}
  <li>{{ item }}</li>
  {% endfor %}
  </ul>
  {% endfor %}
  </div>
  ```

  ```html example.html theme={null}
  <div class="columwrapper">
  <ul class="column-1">
  <li>laptops</li>
  <li>tablets</li>
  <li>smartphones</li>
  </ul>

  <ul class="column-2">
  <li>smart watches</li>
  <li>TVs</li>
  <li></li>
  </ul>
  </div>
  ```
</CodeGroup>

| パラメーター   | タイプ | 説明                   |
| -------- | --- | -------------------- |
| `slices` | 数値  | スライスされる項目の数。         |
| `filler` | 文字列 | 空白のスライスに埋める文字を指定します。 |

## sort

反復可能データを並べ替えます。このフィルターを使ってHubSpotで属性を基準に並べ替える際には、全てのパラメーターが必須です。最初のパラメーターは、並べ替え順序を逆にするブール値です。2番目のパラメーターは、並べ替えで大文字と小文字を区別するかどうかを決定します。最後のパラメーターは、並べ替え基準となる属性を指定します。以下の例ではブログ内の記事が、名前のアルファベット順でレンダリングされます。

<CodeGroup>
  ```html example.html theme={null}
  {% set my_posts = blog_recent_posts("default", limit=5) %}

  {% for item in my_posts|sort(False, False, "name") %}
  {{ item.name }}<br>

  {% endfor %}
  ```

  ```html example.html theme={null}
  A post<br />
  B post<br />
  C post<br />
  D post<br />
  E post<br />
  ```
</CodeGroup>

| パラメーター           | タイプ  | 説明                               |
| ---------------- | ---- | -------------------------------- |
| `reverse`        | ブール値 | 並べ替え順序を逆にするには、`true`に設定します。      |
| `case_sensitive` | ブール値 | `true`に設定すると、並べ替えで大文字と小文字が区別されま。 |
| `attribute`      | 文字列  | 並べ替えの基準となる属性。リストを並べ替えるときには省略します。 |

## split

入力文字列を特定の区切り文字で分割して、リストにします。最初のパラメーターは、変数を分割する基準となる区切り文字を指定します。2番目のパラメーターは、変数の分割回数を決定します。残りの項目が存在する場合、それらはグループ化されたままになります。以下の例では、複数の名前からなる1つの文字列が`;`を基準に最初の4回だけ分割されます。

<CodeGroup>
  ```html example.html theme={null}
  {% set string_to_split = "Mark; Irving; Helly; Dylan; Milchick; Harmony;" %}
  {% set names = string_to_split|split(";", 4) %}
  <ul>
  {% for name in names %}
  <li>{{ name }}</li>
  {% endfor %}
  </ul>
  ```

  ```html example.html theme={null}
  <ul>
  <li>Mark</li>
  <li>Irving</li>
  <li>Helly</li>
  <li>Dylan; Milchick; Harmony;</li>
  </ul>
  ```
</CodeGroup>

| パラメーター                  | タイプ | 説明                                              |
| ----------------------- | --- | ----------------------------------------------- |
| `character_to_split_by` | 文字列 | 変数を分割する区切り文字を指定します。                             |
| `number_of_splits`      | 数値  | 変数を分割する回数を指定します。残りの項目（存在する場合）は、グループ化されたままになります。 |

## string

他の型の変数を文字列に変換します。以下の例では、整数が文字列に変換されます（変数の型の変化を確認するために`pprint`を使用しています）。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set number_to_string = 45 %}
  {{ number_to_string|string|pprint }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  (String: 45)
  ```
</CodeGroup>

## striptags

SGML/XMLタグを除去して、隣接する空白を1つのスペースで置換します。このフィルターは、変数内のHTMLタグを除去する際に使用できます。

<CodeGroup>
  ```html example.html theme={null}
  {% set some_html = "<div><strong>Some text</strong></div>" %}
  {{ some_html|striptags }}
  ```

  ```html example.html theme={null}
  some text
  ```
</CodeGroup>

## strtodate

日付文字列と日付形式を日付オブジェクトに変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ '3/3/21'|strtodate('M/d/yy') }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  2021-03-03 00:00:00
  ```
</CodeGroup>

| パラメーター       | タイプ | 説明                                                                                         |
| ------------ | --- | ------------------------------------------------------------------------------------------ |
| `dateFormat` | 文字列 | 使用する[日付形式](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)（英語）。 |

## strtotime

日時文字列と日時書式を変換して、日時オブジェクトにします。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  1531558890000
  ```
</CodeGroup>

| パラメーター           | タイプ | 説明                                                                                             |
| ---------------- | --- | ---------------------------------------------------------------------------------------------- |
| `datetimeFormat` | 文字列 | 使用する[日付と時刻の形式](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)（英語）。 |

## sum

シーケンス内の数値を全て合算します。最初のパラメーターには任意の属性を指定し、2番目のパラメーターには、変数内に加算するものがない場合に返す値を設定します。

<CodeGroup>
  ```text hubl.txt theme={null}
  // Simple sum
  {% set sum_this = [1, 2, 3, 4, 5] %}
  {{ sum_this|sum }}

  // Sum of attribute
  {% set items = [15, 10] %}
  {% set dict_var = [{"name": "Item1", "price": "20"}, {"name": "Item2", "price": "10"}] %}
  Total: {{ dict_var|sum(attribute="price") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  15 Total: 30
  ```
</CodeGroup>

| パラメーター              | タイプ | 説明                   |
| ------------------- | --- | -------------------- |
| `attribute`         | 文字列 | 合計する属性。              |
| `return_if_nothing` | 文字列 | 変数内に加算するものがない場合に返す値。 |

## symmetric\_difference

2つのセットまたはリストの対称差を返します。フィルターから返されるリストには、1つ目のリストに含まれ、2つ目には含まれない一意の要素、または2つ目のリストに含まれ、1つ目には含まれない一意の要素が全て格納されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ [1, 2, 3]|symmetric_difference([2, 3, 4, 5]) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [1, 4, 5]
  ```
</CodeGroup>

| パラメーター | タイプ | 説明                               |
| ------ | --- | -------------------------------- |
| `list` | 整列  | 1つ目のリストとの対称差を見つけるために比較する2つ目のリスト。 |

## title

見出し表記の値を返します。つまり、英単語の先頭が大文字に、残りの文字は全て小文字になります。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_title="my title should be title case" %}
  {{ my_title|title }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  My Title Should Be Title Case
  ```
</CodeGroup>

## tojson

オブジェクトをJSON文字列として書き出します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% for content in contents %}
  {{ content.blog_post_author|tojson }}
  {% endfor %}
  ```

  ```json example.json theme={null}
  {
  "portalId": 1234567,
  "id": 12312253109,
  "created": 1566413741989,
  "updated": 1566414012799,
  "deletedAt": 0,
  "fullName": "Sample User",
  "email": "sampleUser@example.com",
  "userId": null,
  "username": null,
  "slug": "sample-user",
  "jsonBody": {
  "avatar": "https://app.hubspot.com/settings/avatar/109d6874a0cb066c1c7263ac5df6ce7a",
  "bio": "Sample Bio",
  "facebook": "",
  "linkedin": "",
  "twitter": "",
  "website": "https://www.hubspot.com"
  },
  "bio": "Sample Bio",
  "facebook": "",
  "linkedin": "",
  "avatar": "https://app.hubspot.com/settings/avatar/109d6874a0cb066c1c7263ac5df6ce7a",
  "gravatarUrl": "https://app.hubspot.com/settings/avatar/108bb5ac667ded34796271437dfe8d58",
  "twitterUsername": "",
  "hasSocialProfiles": false,
  "website": "https://www.hubspot.com",
  "twitter": "",
  "displayName": "Sample User"
  }
  ```
</CodeGroup>

## trim

先頭および末尾にある空白を除去します。包括的な説明のためにここで説明していますが、HubSpotでは標準でマークアップから前後の空白が削除されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ " remove whitespace " }}
  {{ " remove whitespace "|trim }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  remove whitespace remove whitespace
  ```
</CodeGroup>

## truncate

特定の文字数よりも後ろにあるテキストを切り捨てます。デフォルトは255文字です。このカウントにはHTML文字が含まれます。

<Warning>
  **注**: このフィルターは単語間のスペースを使用して文字列を短縮するため、日本語などの文字間にスペースがない言語では期待どおりに機能しないことがあります。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ "I only want to show the first sentence. Not the second."|truncate(40) }}
  {{ "I only want to show the first sentence. Not the second."|truncate(35, true, "..........") }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  I only want to show the first sente..........
  ```
</CodeGroup>

| パラメーター                 | タイプ  | 説明                                                   |
| ---------------------- | ---- | ---------------------------------------------------- |
| `number_of_characters` | 数値   | テキストが切り捨てられる前の許容文字数。デフォルト値は255文字です。                  |
| `breakword`            | ブール値 | `true`の場合、長さでテキストが切り捨てられます。`false`の場合は、最後の単語が除去されます。 |
| `end`                  | 文字列  | 切り捨て後に付加されるデフォルトの記号「...」を変更します。                      |

## truncatehtml

HTMLマークアップを考慮しながら（つまり、ネストしている全てのタグが適切に閉じられ）、特定の文字列を切り捨てます。これにより、切り捨て後にタグが開いたままになることが防止されます。HTML文字は、合計文字数にカウントされません。

<Warning>
  **注**: このフィルターは単語間のスペースを使用して文字列を短縮するため、日本語などの文字間にスペースがない言語では期待どおりに機能しないことがあります。
</Warning>

<CodeGroup>
  ```html example.html theme={null}
  {% set html_text = "<p>I want to truncate this text without breaking my HTML<p>" %}
  {{ html_text|truncatehtml(28, "..." , false) }}
  ```

  ```html example.html theme={null}
  <p>I want to truncate this..</p>
  ```
</CodeGroup>

| パラメーター                 | タイプ  | 説明                                                                                                                                                   |
| ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `number_of_characters` | 数値   | テキストが切り捨てられる前の許容文字数。デフォルト値は255文字です。                                                                                                                  |
| `end`                  | 文字列  | 切り捨て後に付加されるデフォルトの記号「...」を変更します。                                                                                                                      |
| `breakword`            | ブール値 | ブール値。`true`の場合、長さでテキストが切り捨てられます。`false`（デフォルト）の場合は、最後の単語が除去されます。任意のパラメーターのうち1つだけを使用する場合は、例えば`truncatehtml(70, breakwords = false)`のようにキーワード引数を使用します。 |

## unescape\_html

HTMLエンコードされたエンティティーを含むテキストを同等のUnicodeに変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set escape_string = "me & you" %}
  {{ escape_string|unescape_html }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  me & you
  ```
</CodeGroup>

## union

2つのセットまたはリストの共通部分を返します。フィルターから返されるリストには、いずれかのリストに含まれる一意の要素が全て格納されます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ [1, 2, 3]|union([2, 3, 4, 5]) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [1, 2, 3, 4, 5]
  ```
</CodeGroup>

| パラメーター | タイプ | 説明                       |
| ------ | --- | ------------------------ |
| `list` | 整列  | 1つ目のリストに対して結合される2つ目のリスト。 |

## unique

オブジェクトのシーケンスまたはディクショナリーから一意のセットを抽出します。（関数から戻される記事リストなどの）ディクショナリーをフィルタリングする場合、どの属性を基準にディクショナリー項目の重複を削除するかを指定できます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set my_sequence = ["one", "one", "two", "three" ] %}
  {{ my_sequence|unique }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  [one, two, three]
  ```
</CodeGroup>

| パラメーター | タイプ | 説明                            |
| ------ | --- | ----------------------------- |
| `attr` | 文字列 | ディクショナリー値を絞り込む際に使用する属性を指定します。 |

## unixtimestamp

日時オブジェクトをUnixタイムスタンプに変換します。

<Warning>
  ### 注:

  このフィルターは、日付を返す変数で<u>のみ</u>使用してください。2024年9月30日以降、このフィルターはnull値が渡された場合に現在の日付を返さなくなります。この日付を過ぎると、フィルター内のnull値は`September 30, 2024`を返します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ local_dt }}
  {{ local_dt|unixtimestamp }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  2017-01-30 17:11:44 1485814304000
  ```
</CodeGroup>

## upper

値に含まれる全ての文字を大文字に変換します。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set text="text to make uppercase" %}
  {{ text|upper }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  TEXT TO MAKE UPPERCASE
  ```
</CodeGroup>

## urlencode

文字列をエスケープしてUTF-8形式でURLエンコードします。ディクショナリーと通常の文字列、およびペアワイズ反復を受け入れます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set encode_value="Escape & URL encode this string" %}
  {{ encode_value|urlencode }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Escape+%26+URL+encode+this+string
  ```
</CodeGroup>

## urldecode

エンコードされたURL文字列を元のURLにデコードします。ディクショナリーと通常の文字列、およびペアワイズ反復を受け入れます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set decode_value="Escape+%26+URL+decode+this+string" %}
  {{ decode_value|urldecode }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Escape & URL decode this string
  ```
</CodeGroup>

## urlize

プレーンテキスト内のURLを、クリック可能なリンクに変換します。追加的な整数をこのフィルターに渡した場合、URLがその数値に短縮されます。2番目のパラメーターは、リンクをrel="no follow"にするかどうかを指示するブール値です。最後のパラメーターでは、リンクを新しいタブで開くかどうかを指定できます。

| パラメーター            | タイプ  | 説明                                        |
| ----------------- | ---- | ----------------------------------------- |
| `shorten_text`    | 数値   | URLを指定の数に短縮する整数。                          |
| `no_follow`       | ブール値 | `true`に設定すると、リンクに`rel="no follow"`が含まれます。 |
| `target="_blank"` | 文字列  | リンクを新しいタブで開くかどうかを指定します。                   |

<CodeGroup>
  ```text hubl.txt theme={null}
  {{ "http://hubspot.com/"|urlize }}
  {{ "http://hubspot.com/"|urlize(10,true) }}
  {{ "http://hubspot.com/"|urlize("",true) }}
  {{ "http://hubspot.com/"|urlize("",false,target="_blank") }}
  ```

  ```html example.html theme={null}
  <a href="https://developers.hubspot.jp/docs//hubspot.com/">http://hubspot.com/</a>
  <a href="https://developers.hubspot.jp/docs//hubspot.com/" rel="nofollow">http://...</a>
  <a href="https://developers.hubspot.jp/docs//hubspot.com/" rel="nofollow">http://hubspot.com/</a>
  <a href="https://developers.hubspot.jp/docs//hubspot.com/" target="_blank">http://hubspot.com/</a>
  ```
</CodeGroup>

## wordcount

文字列内の単語数をカウントします。

<Warning>
  HTMLが含まれている文字列の正確なカウントを取得する場合は、`striptags`フィルターを使用します。
</Warning>

<CodeGroup>
  ```text hubl.txt theme={null}
  {%  set count_words = "Count the number of words in this variable"  %}
  {{ count_words|wordcount }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  8
  ```
</CodeGroup>

## wordwrap

指定された文字数で折り返します。HubSpotではデフォルトで空白が除去されるため、この機能は`<pre>`で特に役立ちます。

<CodeGroup>
  ```text hubl.txt theme={null}
  {% set wrap_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam efficitur, ipsum non sagittis euismod, ex risus rhoncus lectus, vel maximus leo enim sit amet dui. Ut laoreet ultricies quam at fermentum." %}
  {{ wrap_text|wordwrap(10) }}
  ```

  ```text 出力のレンダリング.txt theme={null}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam efficitur, ipsum
  non sagittis euismod, ex risus rhoncus lectus, vel maximus leo enim sit amet
  dui. Ut laoreet ultricies quam at fermentum.
  ```
</CodeGroup>

| パラメーター            | 説明             |
| ----------------- | -------------- |
| `character_count` | コンテンツを折り返す文字数。 |

## xmlattr

ディクショナリー内の項目に基づいてHTML/XML属性文字列を作成します。「値なし」および未定義値を除き、全ての値が自動的にエスケープされます。最初のパラメーターがfalseの場合以外は、フィルターから返された項目の前に自動的にスペースが追加されます。

<CodeGroup>
  ```html example.html theme={null}
  {% set html_attributes = {"class": "bold", "id": "sidebar"} %}
  <div {{ html_attributes|xmlattr }}></div>
  ```

  ```html example.html theme={null}
  <div class="bold" id="sidebar"></div>
  ```
</CodeGroup>

| パラメーター      | タイプ  | 説明                             |
| ----------- | ---- | ------------------------------ |
| `autospace` | ブール値 | 項目の前にスペースを追加するには、`true`に設定します。 |
