> For the complete documentation index, see [llms.txt](https://manual.dxable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.dxable.com/1password/template-syntax.md).

# テンプレート構文

[シークレット参照](https://developer.1password.com/docs/cli/secret-reference-syntax/)を含むテンプレート化された構成ファイルをCreateし、[op inject を使用して](https://developer.1password.com/docs/cli/secrets-config-files/)実際のシークレットを含む解決済みの構成ファイルを受け取ることができます。

プレーンテキストのシークレットの代わりに、囲まれたシークレット参照を含むテンプレート ファイルの例を次に示します。

{% code title="" %}

```
database:
  host: localhost
  port: 5432
  username: {{ op://prod/database/username }}
  password: {{ op://prod/database/password }}
```

{% endcode %}

### **シークレット参照** <a href="#o9i83bbbozfk" id="o9i83bbbozfk"></a>

[テンプレート ファイルに含まれるシークレット参照は、囲まれていないシークレット参照](https://developer.1password.com/docs/cli/secrets-template-syntax/#unenclosed-secret-references)または[囲まれたシークレット参照](https://developer.1password.com/docs/cli/secrets-template-syntax/#enclosed-secret-references)のいずれかとしてフォーマットできます。

#### **非公開の秘密参照** <a href="#q53aoig2deif" id="q53aoig2deif"></a>

```
$ op://test-app/database/password
```

囲まれていない秘密参照は次のような文字列です。

* `op://` で始まり、`英数字`、`-`、`+`、 `\`、`..`のいずれの`op://`文字も前には来ません。
* テンプレートの終わり、`または英数字`、`-`、`?`、`_`、`..` のセット外で最初に見つかった文字で終わります。

囲まれていない秘密の参照の良い例と悪い例:

```
op://prod/docker-credentials/username
```

```
op://d3v/stripe.keys/s3ct10n/public_key
```

```
op://h?ack/1Password!/for"real
```

(構文でサポートされていない特殊文字が含まれています)

```
op://{vault}/[item]/(section)/field
```

(構文でサポートされていない特殊文字が含まれています)

#### **Enclosed secret references** <a href="#sdvcvfmm6nk7" id="sdvcvfmm6nk7"></a>

```
$ {{ op://test-app/database/password }}
```

囲まれた秘密参照は、次のすべてを満たす文字列として定義されます。

* 2つの閉じ括弧で始まる`{{`
* 2つの閉じ括弧で終わる`}}`
* 2 組の中括弧の間には、有効な囲まれていない秘密参照が含まれます。スペースが埋め込まれている場合もあります。

良い秘密参照と悪い秘密参照の例:

```
{{op://prod/docker-credentials/username}}
```

```
{{ op://d3v/stripe.keys/s3ct10n/public_key }}
```

```
{{op://h?ack/1Password!/for"real}}
```

(秘密の参照にはサポートされていない文字が含まれています)

#### **特殊文字** <a href="#vo9ogw1pshkb" id="vo9ogw1pshkb"></a>

テンプレート内の特殊文字をエスケープする必要がある場合は、中括弧と二重引用符を使用できます。

```
{{ "{{ test op://prod/docker-credentials/username }}" }}
will be resolved to
{{ test op://prod/docker-credentials/username }}
```

コンテンツに二重引用符が含まれている場合は、次のようにエスケープする必要があります`\`。

```
{{ "{{ test \"test\" test }}" }}
will be resolved to
{{ test "test" test }}
```

### **変数** <a href="#id-4t5pi3uv99f1" id="id-4t5pi3uv99f1"></a>

テンプレート構文は変数タグもサポートします。

* `$var`(囲まれていない変数)
* `${var}`(囲まれた変数)

形式の囲まれていない変数を解決すると`$FOO`、 という名前の環境変数の値に置き換えられます`FOO`。

形式の囲まれた変数を解決する場合`${FOO}`、 の先頭または末尾の空白は`FOO`破棄され、参照は という名前の環境変数の値に置き換えられます`FOO`。

変数名は大文字と小文字を区別せず、数字で始めることはできず、文字、数字、アンダースコアのみを含めることができます。

囲まれていない変数の良い例と悪い例:

```
$my_var
```

```
$mY_2nd_vAr
```

```
$2nd_var
```

(数字で始まる)

```
$var-?notvar!
```

(サポートされていない特殊文字が含まれています)

囲まれた変数の良い例と悪い例:

```
${my_var}
```

```
${ mY_2nd_vAr }
```

```
${my_var\}
```

(閉じ括弧はエスケープされます)

#### **デフォルト値** <a href="#wmq721fbkem" id="wmq721fbkem"></a>

テンプレート変数のデフォルト値を設定するには、次の構文を使用します。

`${VAR_NAME:-<default-value>}`

環境内で変数が見つからない場合は、デフォルト値が使用されます。

例えば、VAULT 環境変数が設定されていない場合、`op://${VAULT:-dev}/docker/password` は `op://dev/docker/password` と評価されます。 `VAULT` が `prod` に設定されている場合、`op://prod/docker/password` として評価されます。

### **さらに詳しく** <a href="#juowdyy8dz74" id="juowdyy8dz74"></a>

* [シークレットを構成ファイルに読み込む](https://developer.1password.com/docs/cli/secrets-config-files/)
* [環境にシークレットをロードする](https://developer.1password.com/docs/cli/secrets-environment-variables/)
* [秘密参照構文](https://developer.1password.com/docs/cli/secret-reference-syntax/)


---

# 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:

```
GET https://manual.dxable.com/1password/template-syntax.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.
