Call value stored in handle based on string

I am trying to pull through data into a reconciliation from an account template. It works when I use the following code;

{{ period.reconciliations.maz_fx_rates.results.datapoint_1612051200_USD }}

however when I try to make this dynamic and build the string above it does not pull through the data. I am using the following code

{% assign current_date_seconds = period.end_date | date:“%s” %}
{{current_date_seconds | text}}
{% capture datapoint %}{{current_date_seconds}}{% endcapture %}
{%assign datapointString = ‘period.reconciliations.maz_fx_rates.results.datapoint_’ | append: current_date_seconds | String %}

{{ datapointString; }}

Hi @James

In order to fetch the result, the result name should first be defined.
The second issue is that you’re converting the reference to the result to a string.
By doing so, that piece of code will not be executed when you print it.

What would work is the following, based on the result name you mentioned:

{% assign current_date_seconds = period.end_date | date:"%s" %}
{% capture result_name %}datapoint_{{ current_date_seconds }}_USD{% endcapture %}
{% assign result_value = period.reconciliations.maz_fx_rates.results.[result_name] %}

If the USD isn’t fixed, that could be determined in a local variable just like current_date_seconds.

So you first need to get the entire result name in a dynamic variable (result_name).
Then you can use that result name to access the actual result from the template.

Note that you need to apply square brackets around the result name because it’s a dynamic variable, and that the local var result_value is not a string, so no apostrophes.

Hope this helps you along!
Kind regards,
Romy