# Nested and Referenced Variables

Source: https://www.jawsdeploy.net/guides/nested-and-referenced-variables

References use `#{Variable.Name}` syntax and can chain through several layers without copy-paste.

Variables can reference other variables. The syntax is `#{Variable.Name}`. References resolve recursively at deployment time, so a chain of references collapses into a single final value before the step runs.

## Three variables, one resolved value

Reduces the duplication in connection strings and URLs.

```
Db.Host       = "prd-sql-#{Region}.internal"
Db.Name       = "app_#{Environment}"
Db.Connection = "Server=#{Db.Host};Database=#{Db.Name};Trusted_Connection=yes"

Region            (env=Production)     = "eu-west"
Environment       (env=Production)     = "prd"

Resolved value of Db.Connection in Production (eu-west):
  Server=prd-sql-eu-west.internal;Database=app_prd;Trusted_Connection=yes
```

## Why this matters

Without composition, every connection string in every environment is its own variable, and changing the database server name requires editing N values. With composition, `Db.Host` is one variable scoped per environment, and the rest follows.

> **// Cycles - The platform detects and rejects cycles.**
> 
> If `A` references `B` and `B` references `A`, the deployment fails with a clear error pointing at the cycle. The same applies to deeper chains - if any path leads back to the starting variable, the resolution stops.

## Token replacement in files

The same `#{Variable.Name}` syntax works inside config files. A package deployment step with **substitute variables in files** enabled walks the listed files and replaces tokens before the package is placed on the target. Useful for `appsettings.json`, `web.config`, custom INI files, and similar.

