CASE: select different sections of text and overview them

Let’s say I have different reconciliation templates where f.i. a bunch of footnotes are given; these footnotes is some standard text with info in it (info that I have in my client file and can call upon, and other variable text), but I should be able to adapt that presented text as well.
The goal is to have an overview of all footnotes in one doc; not all footnotes should be in the overview however, if I can choose this.

Let’s build the reconciliation templates first, where I want to have generic coding that can be used for each template for the footnotes.

All recon templates with the generation of the footnotes will be give a handle that starts with footnotes_ and add the number to that handle as well (to order the overview of all footnotes per each template / category of footnotes).
f.i. footnotes_1, footnotes_2, …

I will use those uniques handles to loop over all recon templates that have footnotes_ in their name of handle.

Now, on to making recon template 1:

{% ic %}
{::infotext}
{% t "Select the footnotes that need to be taken in the export; an overview of all checked footnotes can be seen in the text template Footnotes" %}
{:/infotext}
{% endic %}

Just an infotag to guide the user what to do with the template.

{% assign end_date = period.end_date | date:"%m-%d-%y" %}
{% assign company = company.name | upcase | append:" " | append:company.company_form %} 

Create some variables that I need in my standard text.

{% capture footnote_1 %}
This footnote describes the done costs for software untill {{ end_date }}; an overview can be given if needed. 
{% endcapture %}

{% capture footnote_2 %}
{{ company }} has decided to depreciate these investments following the rules as depicted... 
{% endcapture %}

We capture the text we want to display, together with the variables. The capture (which is basically only
the output of coding and/or text) will be used as default in an input database variable we will create later on.

{% comment %}
create array to loop over and create all input notes 
<!----------- if new footnote needs to be made, then add it to each variable below -------------->
{% endcomment %}
{% assign array_notes = "note_1;note_2" | split:";" %}
{% assign array_footnotes = "footnote_1;footnote_2" | split:";" %} 

We will create an array to loop over array_notes but also a second one which has the names of our captures. That’s very important; so both arrays need to have the same amount of elements too.

{% comment %}create input notes with option to check{% endcomment %}
{% stripnewlines %}
|----5%----
|----------+
{% for item in array_notes %}
  {% newline %}
    | {% input custom.show.array_footnotes[forloop.index0] as:boolean %}
      {% comment %}re-create capture of each footnote{% endcomment %}
      {% capture cap_footnote %}{{ array_footnotes[forloop.index0] }}{% endcapture %}
    | {% input custom.txt.array_footnotes[forloop.index0] as:text size:mini default:[cap_footnote] %}
      {% assign input_txt = custom.txt.array_footnotes[forloop.index0] | default:[cap_footnote] %}
      {% if custom.show.array_footnotes[forloop.index0] == "true" %}
        {% result cap_footnote input_txt %}
      {% endif %}  
{% endfor %}
{% endstripnewlines %} 

This needs diving into it a little deeper:

{% for item in array_notes %}

We’ll go thorugh the elements of the first array to create the needed input database variables

{% input custom.show.array_footnotes[forloop.index0] as:boolean %}

While we are looping through the original array, we’ll loop through the second one together as well.
So the first loop actually has custom.show.footnote_1 as name of the database variable, in the second loop custom.show.footnote_2 and so on…

{% comment %}re-create capture of each footnote{% endcomment %}
{% capture cap_footnote %}{{ array_footnotes[forloop.index0] }}{% endcapture %}

In each loop we will create dynamic variable names.
So in the first loop we’ll have the variable footnote_1, in the second footnote_2, …
More info on dynamic variables here:

{% input custom.txt.array_footnotes[forloop.index0] as:text size:mini default:[cap_footnote]

We’ll create a database variable but with the default the dynamic variable of the footnotes. So not the name of the variable {{ cap_footnote }} which will only print “footnote_1” in the first loop, but {{ [cap_footnote] }} which will give the value of our capture (the default text with variables in it).

{% assign input_txt = custom.txt.array_footnotes[forloop.index0] | default:[cap_footnote] %}

We do need to add this into a variable because our database variable is actually empty when using a default. This can be done with the default-method: if the database variable is empty (and that’s the case if you don’t change anything of the default text), the argument in the default method will be assigned to the variable. If it’s not empty, the value of the database variable will be assigned to that variable input_txt.

{% if custom.show.array_footnotes[forloop.index0] == “true” %}
{% result cap_footnote input_txt %}
{% endif %}

When the boolean has been checked, only the we’ll take the variable input_txt into a result tag.

Here’s the complete code of template 1 (software):

{% ic %}
{::infotext}
{% t "Select the footnotes that need to be taken in the export; an overview of all checked footnotes can be seen in the text template Footnotes" %}
{:/infotext}
{% endic %}

{% assign end_date = period.end_date | date:"%m-%d-%y" %}
{% assign company = company.name | upcase | append:" " | append:company.company_form %}


{% capture footnote_1 %}
This footnote describes the done costs for software untill {{ end_date }}; an overview can be given if needed. 
{% endcapture %}

{% capture footnote_2 %}
{{ company }} has decided to depreciate these investments following the rules as depicted... 
{% endcapture %}


{% comment %}
create array to loop over and create all input notes 
<!----------- if new footnote needs to be made, then add it to each variable below -------------->
{% endcomment %}
{% assign array_notes = "note_1;note_2" | split:";" %}
{% assign array_footnotes = "footnote_1;footnote_2" | split:";" %}


{% comment %}create input notes with option to check{% endcomment %}
{% stripnewlines %}
|----5%----
|----------+
{% for item in array_notes %}
  {% newline %}
    | {% input custom.show.array_footnotes[forloop.index0] as:boolean %}
      {% comment %}re-create capture of each footnote{% endcomment %}
      {% capture cap_footnote %}{{ array_footnotes[forloop.index0] }}{% endcapture %}
    | {% input custom.txt.array_footnotes[forloop.index0] as:text size:mini default:[cap_footnote] %}
      {% assign input_txt = custom.txt.array_footnotes[forloop.index0] | default:[cap_footnote] %}
      {% if custom.show.array_footnotes[forloop.index0] == "true" %}
        {% result cap_footnote input_txt %}
      {% endif %}  
{% endfor %}
{% endstripnewlines %}

Example of generic coding into a second template (office material f.i.), where we add a third footnote in both array, and create an extra capture. Other than that, we don’t need to change any code!

{% ic %}
{::infotext}
{% t "Select the footnotes that need to be taken in the export; an overview of all checked footnotes can be seen in the text template Footnotes" %}
{:/infotext}
{% endic %}

<br>

{% assign end_date = period.end_date | date:"%m-%d-%y" %}
{% assign company = company.name | upcase | append:" " | append:company.company_form %}


{% capture footnote_1 %}
This footnote describes the done investments for office material untill {{ end_date }}; an overview can be given if needed. 
{% endcapture %}

{% capture footnote_2 %}
{{ company }} has decided to depreciate these investments following the rules as depicted... 
{% endcapture %}

{% capture footnote_3 %}
Extra information if needed 
{% endcapture %}


{% comment %}
create array to loop over and create all input notes 
<!----------- if new footnote needs to be made, then add it to each variable below -------------->
{% endcomment %}
{% assign array_notes = "note_1;note_2;note_3" | split:";" %}
{% assign array_footnotes = "footnote_1;footnote_2;footnote_3" | split:";" %}

{% comment %}create input notes with option to check{% endcomment %}
{% stripnewlines %}
|----5%----
|----------+
{% for item in array_notes %}
  {% newline %}
    | {% input custom.show.array_footnotes[forloop.index0] as:boolean %}
      {% comment %}re-create capture of each footnote{% endcomment %}
      {% capture cap_footnote %}{{ array_footnotes[forloop.index0] }}{% endcapture %}
    | {% input custom.txt.array_footnotes[forloop.index0] as:text size:mini default:[cap_footnote] %}
      {% assign input_txt = custom.txt.array_footnotes[forloop.index0] | default:[cap_footnote] %}
      {% if custom.show.array_footnotes[forloop.index0] == "true" %}
        {% result cap_footnote input_txt %}
      {% endif %}  
{% endfor %}
{% endstripnewlines %}

Let’s overview all these footnotes in 1 text template (I use a text template so I can easily preview), and we can use this case for it:

in where we loop over recon templates and display the values of their result tags. Obviously, we’ll need to add some logic to it:

{% stripnewlines %}
|-----+
{% for item in period.reconciliations %}
  {% if item.handle contains "footnotes" %}
    {% newline %}
    | {::font size="l"}**{% linkto period.reconciliations.[item.handle] %}{{ item.name }}{% endlinkto %}** {:/font}
      {% for item in period.reconciliations.[item.handle].results %}
        {% if item[0] contains "footnote_" %}
          {% newline %}
          | {{ item[1] }} 
        {% endif %}
      {% endfor %}
  {% endif %}
{% endfor %}
{% endstripnewlines %}

So, let’s dive into that:

{% for item in period.reconciliations %}

Looping over all recon templates

{% if item.handle contains “footnotes” %}

{{ item.handle }} will give the name of the used handle, and we know each handle with footnotes has footnotes in it

{::font size=“l”}{% linkto period.reconciliations.[item.handle] %}{{ item.name }}{% endlinkto %} {:/font}

We’ll create a linkto to that specific template (perhaps a user wants to excluse a text from the overview) and display the name of the template as well.

{% for item in period.reconciliations.[item.handle].results %}

For each found recon template, we’ll loop over all result tags that can be found in it

{% if item[0] contains “footnote_” %}

Each footnote starts with “footnote_” as the name of the result-tag.

{{ item[1] }}

With this variable we’ll have the value of the result-tag (with {{ item[0] }} the name of the result-tag itself).

This is the outcome: