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

# 変数と式

ページやセクションで参照できる再利用可能な変数を作成します

変数を使うと、次の場所で条件に応じて参照できる再利用可能なテキストを作成できます。 [式](https://gitbook.com/docs/documentation/ja-gitbook-documentation/kontentsuwosuru/formatting/inline.md#expressions) や [アダプティブコンテンツの条件](https://gitbook.com/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/adapting-your-content.md#working-with-the-condition-editor).

コンテンツ内で同じ名前、フレーズ、バージョン番号を何度も繰り返す場合は、 **変数** を作成すると、すべての箇所を同期させて正確に保てます。更新が必要な場合や、複雑で入力ミスが起こりやすい場合に便利です。

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

### 新しい変数を作成

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

上部の切り替えを使って、現在のページにスコープされた変数、または現在のセクション内のすべてのページにスコープされた変数を表示・作成できます。

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

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

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-c8a49c22f14f326ac8f05fd190051c8a5dd0c6bd%2F25_12_10_add_variable%402x.png?alt=media" 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 %}

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

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

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

ページ内で定義した変数は、 `page.vars` オブジェクトから利用できます。同様に、セクション全体で定義した変数は、 `space.vars` オブジェクトから利用できます。

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

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-8e364840ff56aaf06150756001d44c2cf1292410%2F25_12_10_add_variable%402x_1.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
