Oftentimes I find myself in a position where I think I need to have a dynamic variable name. For example, if you need to store contents in unique variables, but you don’t know how many you’ll need (like a dynamic loop). Here’s some code to illustrate:
In this case, we don’t know what years will be in the dataset, but we need to be able to reference each value uniquely, hence we use a dynamic variable name. To get at the values in these dynamic variables, we have to use evaluate:
However, evaluate can slow down the page processing. So wouldn’t it be better to use an array or structure? Then we can just access them without having to play games with variable names: