Variables with variable names (eg fiscal parameters)

Hey,

Have a small problem here as I’m trying to access a different value according to a parameter:

In a file with the handle ‘Parameters’, I specified the following variables:

{% assign RevCoe_BelTij2016 = 4.31 %}
{% assign RevCoe_BelTij2015 = 4.23 %}

I then put them in a result tag

{% result “RevCoe_BelTij2016” RevCoe_BelTij2016 %}
{% result “RevCoe_BelTij2015” RevCoe_BelTij2015 %}

In another file, I typed the following code:

{% assign BelTij = period.year_end_date | date:’%Y’ %} (this evaluates to 2016)

{% capture RevCoe_Var %} RevCoe_BelTij{{BelTij}} {% endcapture %}

{% assign RevCoe_Toepasselijk = period.reconciliations.Parameters.results.RevCoe_Var %}

1: {{ period.reconciliations.Parameters.results.RevCoe_BelTij2016 }}
2: {{ RevCoe_Toepasselijk }}

Line with ‘1’ gives the desired result (4.31), the second doesn’t give anything. What am I doing wrong here? I want the script to pick the right value according to the year.

Evening @Bart_Verhaeghe,

Great question, and I suggest to make less code in your template where you are refering to :

{% assign RevCoe_BelTij_2016 = 4.31 %}
{% assign RevCoe_BelTij_2015 = 4.23 %}

{% capture RevCoe_BelTij %}RevCoe_BelTij_{{ period.year_end_date | date:"%Y" }}{% endcapture %}

The variable {{ RevCoe_BelTij }} will give the result of your capture (RevCoe_BelTij_2016 fi), but if you use this code :

{{ [RevCoe_BelTij] }} it will give the result of the variable (so 4.23 for instance).

This can be linked into a result-tag, like you did :

{% result “coeff” RevCoe_BelTij %} 

In your template where you want to get the result (depending on the book year you’re in), you can use this code from now on :

{{ period.reconciliations.community.results.[coeff] }} 

As you see, if a new coefficient has to be added, you only have to add one line of code in your template where the result tags are in!
So less code is our goal to go for.

Can you try with this information, and let uw know if it did the trick?
Great case! :ok_hand:

:bangbang: You had 2 mistakes in your own code though :

  • You need to use the date-filter | date:"%Y"
  • I’d suggest never to use spaces in a capture, because you can’t have variables with a space in it

:question: PS mind to use the corresponding topic “Templates” in the future, with your code in quotes (more info here, thanks! :relaxed:

Hi Sven, OK I will. This worked in one template (great), but not in another (very strange), where I pasted the exact same code, namely:

In the ‘general’ template:

{% assign RevCoe_BelTij2017 = 4.39 %}
{% assign RevCoe_BelTij2016 = 4.31 %}
{% assign RevCoe_BelTij2015 = 4.23 %}
{% assign RevCoe_BelTij2014 = 4.23 %}
{% assign RevCoe_BelTij2013 = 4.19 %}
{% assign RevCoe_BelTij2012 = 4.10 %}
{% assign RevCoe_BelTij2011 = 3.97 %}
{% assign RevCoe_BelTij2010 = 3.87 %}

{% comment %}Bepaal (voor het dossier in kwestie) de coëfficiënten voor 1.het vorige jaar, 2.het huidige jaar{% endcomment %}

{% capture RevCoe_BelTij_Huidig %}RevCoe_BelTij{{ period.year_end_date | date:"%Y" }}{% endcapture %}
{% capture RevCoe_BelTij_Vorig %}RevCoe_BelTij{{ period.year_end_date | date:"%Y" | minus: 1 }}{% endcapture %}

{% result "RevCoe_BelTij_Huidig" [RevCoe_BelTij_Huidig] %}
{% result "RevCoe_BelTij_Vorig" [RevCoe_BelTij_Vorig] %}

{% comment %}Onderdeel parameters DBI-Aftrek {% endcomment %}

{% assign DBI_AanWaaAbs_Min = 2500000 %}
{% assign DBI_AanWaaPer_Min = 0.1 %}

{% result "DBI_AanWaaAbs_Min" DBI_AanWaaAbs_Min %}
{% result "DBI_AanWaaPer_Min" DBI_AanWaaPer_Min %}```

In the 'applied' templates:

```Toepasselijke revalorisatiecoëfficiënt {{period.year_end_date | date:"%Y" }}: {{ period.reconciliations.Parameters.results.RevCoe_BelTij_Huidig }}
Toepasselijke revalorisatiecoëfficiënt {{period.year_end_date | date:"%Y" | minus: 1 }}: {{ period.reconciliations.Parameters.results.RevCoe_BelTij_Vorig }}

DBI 1: {{ period.reconciliations.Parameters.results.DBI_AanWaaAbs_Min | currency }}
DBI 2: {{ period.reconciliations.Parameters.results.DBI_AanWaaPer_Min | percentage }}```

Hey Sven,

Found it … This only works when I add the ‘Parameters’ template to the period in question for the customer. Is there a way to avoid this (in the sense that the parameters file is always included in every period for every client without having to do this manually?

Thanks!

@Bart_Verhaeghe,

It’s pretty normal the template with all the parameters should be added to the working period. But once it’s added, there’s no need to erase it.

:bulb:
You can even activate a warning-tag if the template is missing, like this :

{% if period.reconciliation.parameters != blank %}
code of all the results 
{% else %}
{% ic %}
{::warningtext}
Please add reconciliation template "Parameters" in order to link certain results
{:/warningtext}
{% endic %} 
{% endif %}

Thanks for the very nice tip Sven … tried to implement it but it’s not working … Even for customers where the template ‘Parameters’ has been included, he always shows the warning (as such, period.reconciliation.parameters is always blank) … Any ideas?

Hi Bart

Sven made a little mistake (it has to be reconcilations with an s at the end). That’s why it’s not working. Also try to be consistent. If you put a capital P in your handle (Parameters). Try to use a capital P when you are referring to it as well.

{% if period.reconciliation**s**.**P**arameters != blank %}
code of all the results 
{% else %}
{% ic %}
{::warningtext}
Please add reconciliation template "Parameters" in order to link certain results
{:/warningtext}
{% endic %} 
{% endif %}

Kind regards

Sam

OK thanks Sam for your comment … Now it does what it has to …

Have a great day!

Great I could help Bart.
Have a nice day!

Hello Sam,

A related question: is it also possible to refer to an accounts template (like ‘Kapitaal’) like this? I would like to put an alert in a reconciliation template and a text when the accounts template ‘Kapitaal’ is not available for a given client.

Thanks!

It’s not possible since a single account template can be used for multiple accounts. You can however link to an account using {% linkto account.link %}The thing you want to link{% endlinkto %} or just {{account.link}}

Kind regards