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

# 変数と式

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

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

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

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

### 新しい変数を作成

新しい変数を作成するには、 **ライブラリ** 編集中の開いているドキュメントの目次で [変更リクエスト](/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%2FQwfTEGjsxDThqQFvgOm8%2FAdd%20variable%402x.png?alt=media&amp;token=955216f0-67df-4c96-aece-490cfbbf0271" 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/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%2FaRWyFWMI24Cy2nVZmSzE%2FUsing%20variable%402x.png?alt=media&amp;token=a1999774-f0da-4232-8533-b7e806ddd87c" 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.
