> 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/kontentsuwo/variables-and-expressions.md).

# 変数と式

変数を使うと、条件に応じて参照できる再利用可能なテキストを [式](/docs/documentation/ja-gitbook-documentation/kontentsuwo/formatting/inline.md#expressions) 、 [アダプティブコンテンツの条件](/docs/documentation/ja-gitbook-documentation/gong-kai/adaptive-content/adapting-your-content.md#working-with-the-condition-editor).

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

単一のページ、または単一のセクションにスコープされた変数を作成できます。

### 新しい変数を作成

新しい変数を作成するには、 **ライブラリ** 開いているコンテンツを編集中に、目次内の [変更リクエスト](/docs/documentation/ja-gitbook-documentation/koraborshon/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/kontentsuwo/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/kontentsuwo/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.
