Add a variable to a {urlload} function

Is it possible to make the "GBPUSD" element of this function into a variable that I can change using a {formmenu} option or similar

{note: trim=yes}{urlload: https://api.exchangerate.host/live?source=GBP&currencies=USD&access_key=60ec90c111318d5d0d4fa69355869c5c; done=(res) -> ["response": fromjson(res), "isloading": no]; start=() -> ["isloading": yes]} {if: isloading}Loading...{else}Response: {=response}{endif}{rate=response["quotes"]["GBPUSD"]; trim=yes}{endnote}

Yes, you can do that. Here is an illustration of the same.

{formmenu: name=currency_pair; default=GBPUSD; GBPUSD; GBPEUR; GBPINR; GBPJPY}
{note: trim=yes}{urlload: https://api.exchangerate.host/live?source=GBP&currencies={=right(currency_pair,3)}&access_key=60ec90c111318d5d0d4fa69355869c5c; done=(res) -> ["response": fromjson(res), "isloading": no]; start=() -> ["isloading": yes]} {if: isloading}Loading...{else}Response: {=response}{endif}{rate=response["quotes"][currency_pair]; trim=yes}{endnote}

Thank you again Ashwin. I'm learning more each time I contact the team. Tony

1 Like