General object to bind properties to


It would be really great if there were an object to which one can ‘bind’ general methods and properties to (cfr. the ‘application’ object in Excel VBA).

That way, general functions that can be applied anywhere (such as ‘find the last occurence of a given substring in a string’) only have to be defined once and can be applied to an input that is not linked to either the period or the company object.

I find myself having to repeat some code over and over again (and - as a good friend-programmer once said - the ideal programmer is essentially a very lazy person who doesn’t like to repeat himself … :slight_smile:

Or is there another way to solve this problem?


I feel you @Bart_Verhaeghe

Could you give examples of codes you have to repeat? Because if we think it can be generic and has benefits for other template builders, feel free to ask.

Hi Sven and welcome to our daily talk ;-),

The sequence mentioned below takes a (structured) string in the form of A, B, C and ‘reforms’ it to A, B en C. Not mission critical in any way, but really handy to make an output more readable and ‘human’. So the input parameter (str_VGD_Vennootschappen_Namen) is not bound to a company or a period object.

{% comment %}haal de namen van alle vennootschappen uit de parameters{% endcomment %}
  {% assign str_VGD_Vennootschappen_Namen = period.reconciliations.Parameters.results.VGD_Vennootschappen_Namen | strip %}
  {% assign arr_VGD_Vennootschappen_Namen = str_VGD_Vennootschappen_Namen | split: '|' %}
  {% assign int_XthCommaToReplace = arr_VGD_Vennootschappen_Namen.size | minus: 1 %}

{% comment %}vervang de '|' door ', ' (behalve de laatste door ' en '{% endcomment %}
{% for vennootschap in arr_VGD_Vennootschappen_Namen %}
  {% assign counter = counter | plus:1 %}
  {% if counter == int_XthCommaToReplace %}
    {% assign str_Vennootschappen_Correct = str_Vennootschappen_Correct | append: vennootschap | append: ' en ' %}
  {% else %}
    {% assign str_Vennootschappen_Correct = str_Vennootschappen_Correct | append: vennootschap | append: ', ' %}
  {% endif %}
{% endfor %}

{% assign str_Vennootschappen_Correct_Length = str_Vennootschappen_Correct.size | minus: 2 %}
{% assign str_Vennootschappen_Correct = str_Vennootschappen_Correct | slice: 0, str_Vennootschappen_Correct_Length %}


Hmmm okay, but once this code is made in one template, you can use it everywhere. So I don’t see how your code gets repeated? @Bart_Verhaeghe

Above code is not repeated in other templates, right? It’s only made in 1 template, I assume?

Yes it is … I use this in three templates now.

How can I define this in one template and use it in another then?

Thanks for the great help! Think we’re on to something here …

You can capture that whole code, and take it into a result-tag. Or even better: the outcome of that code can be taken into a result-tag @Bart_Verhaeghe
That way you can use it anywhere else

Why don’t you generate all needed code in that one template with the handle “Parameters”? Think that’s why you made it, no, looking at the name of that handle?