> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/ja-gitbook-documentation/creating-content/variables-and-expressions.md).

# 変数と式

変数を使うと、条件付きで参照できる再利用可能なテキストを作成できます。 [式](/docs/documentation/ja-gitbook-documentation/creating-content/formatting/inline.md#expressions) および [アダプティブコンテンツの条件](/docs/documentation/ja-gitbook-documentation/saitohenoakusesu/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` オブジェクトです。

{% hint style="info" %}
式では、セクションスコープの変数は〜にあります `space.vars` — GitBook APIではセクションを〜として表します `space` オブジェクト。
{% endhint %}

<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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
