# 変数と式

変数を使うと、条件付きで参照できる再利用可能なテキストを [式](/docs/documentation/ja-gitbook-documentation/creating-content/formatting/inline.md#expressions) と [自動適応コンテンツの条件](/docs/documentation/ja-gitbook-documentation/saitoakusesu/adaptive-content/adapting-your-content.md#working-with-the-condition-editor).

コンテンツ内で同じ名前、フレーズ、またはバージョン番号を何度も繰り返す場合は、 **変数** を作成して、それらのすべての箇所を同期させ、正確に保つことができます。これは、更新が必要になったときや、複雑で誤入力が多い場合に役立ちます。

変数は、単一のページまたは単一のスペースにスコープを限定して作成できます。

### 新しい変数を作成する

新しい変数を作成するには、開いている **ライブラリ** の編集時に目次内の [変更リクエスト](/docs/documentation/ja-gitbook-documentation/collaboration/change-requests.md)をクリックし、次に **変数**.

をクリックします。上部の切り替えを使って、現在のページに限定した変数、または現在のスペース内のすべてのページに限定した変数を表示・作成できます。

クリックすると **変数を作成** というモーダルが開き、変数の名前と値を設定できます。

クリック **変数を追加** して変数を保存します。

<figure><img src="/files/879d272192932f6a409fa9e3b3ce6ac914ab5461" alt="A GitBook screenshot showing the Add variables screen. The variable Name box has been filled with the text ‘latest_version’ and the Value box has been filled with the text ‘v3.04.1’"><figcaption><p>変数は、単一のページまたはスペース全体に追加できます。変数の値を更新すると、その変数のすべてのインスタンスが更新されます。</p></figcaption></figure>

{% hint style="info" %}
変数名は文字で始まる必要があり、文字、数字、アンダースコアを含めることができます。
{% endhint %}

### コンテンツ内で変数を使用する

変数は [式](/docs/documentation/ja-gitbook-documentation/creating-content/formatting/inline.md#expressions) 内で参照して使用できます。式はコンテンツ内にインラインで挿入できます。式を挿入したら、ダブルクリックして式エディターを開きます。

{% hint style="info" %}
式は、ドキュメントのページコンテンツ内でのみ使用できます。ページタイトルやページメタデータでは使用できません。
{% endhint %}

ページで定義された変数は、 `page.vars` オブジェクトから参照できます。同様に、スペース全体で定義された変数は、 `space.vars` オブジェクトから参照できます。

<figure><img src="/files/7f94ffc301448324390e071fcd49dfea48c9a115" alt="A GitBook screenshot showing an expression block within the editor. The expression editor is open below it and the ‘space.vars.latest_version’ variable has been selected"><figcaption><p>式内でコンテンツに変数を追加できます。式エディターには、必要な変数を見つけやすくするための自動補完オプションがあります。</p></figcaption></figure>

### 変数を更新する

変更リクエスト内であれば、任意の時点で変数を更新できます。値を更新すると、それを参照しているすべての式ブロックで値が更新されます。変更された変数は、変更リクエストがマージされると、公開済みのサイトに反映されます。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/creating-content/variables-and-expressions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
