Bit of a random question which I am trying it myself and will post an answer if I figure it out. Can you use “$URL/something” in both the UI and the toml file? Which one takes precedence, the UI or build.environment?
If so do you need the " " around it in the UI for the interpolation to replace $URL with the sites main url?
First off, I don’t recommend any pattern of trying to play precedence games between the UI and the toml file; the toml file is ideal to handle ALL variables because it has ability to set a default AND a per-branch or build type context:
# this is the default for all build types not defined specifically below
ACCEPT_URL = "/accept”
CANCEL_URL = "/cancel”
# for the beta branch only
ACCEPT_URL = "/staging/accept"
CANCEL_URL = "/staging/cancel”
Second, you wouldn’t be able to refer to one environment variable from another like that. The values need to be static, and need to be interpolated manually at build time, no matter where you define them. This article has some more details on the successful use of envvars at Netlify:
Specifically, you’ll have to BUILD a value AT BUILD TIME from $URL or $DEPLOY_PRIME_URL plus your path, and you can do contextually different build commands to handle that, something like this (untested but I think it will work)