How to recall a custom form field in the document template?

Dear All,

I am facing this issue:

  • In the registration form, I have added a section
  • Inside this section I have added a custom field in the registration form
  • The field name is “Codice Fiscale” which is a simple text field
  • The field is mandatory

I want to recall the value of this field in the document template for the receipt/invoice but I cannot find out what is the field named in the code (i.e. someting like {{ personal_data.address }} )

Can you help?
thanks in advance
Nik

Ps: I was able to add the field as custom.field but in this case I am required to fill it manually :frowning:

As document template currently can not be linked to a registration form (that is only available for bagde templates) you need to find the field id in the registration.field_data array.

You can e.g. use this snippet:

<pre>
{% for fd in registration.field_data %}
index: {{ loop.index }}
{%- if fd.section_title != "Personal Data" %}
    {{ fd.section_title }}/{{ fd.title }}: {{ fd.friendly_value }}
{% endif -%}
{% endfor %}
</pre>

to find the field index.

Then in the final template use registration.field_data[<index>]....

Please also remember that the sample data in the editing form are generic, so you need to generate a document for a participant first to get meaningful output.

Dear Björn

Thank you so much for your reply.
It saved my day!
I used your code and I figure it out several aspects that I did not know. For instance the fact that the counter start from zero! (i.e. if you need the value in the 7 field as in my case the index is 6!)

I have also included the field as custom field in the metadata in order to overwrite it manually , if necessary. This is the code that is working. I’m just reporting it if anyone else may need it

In template.html:

<!-- [6] is the wanted value in the registration form --> 
  {%- set cf = custom_fields.codice_fiscale or registration.field_data[6].friendly_value %}
     {%- if cf %}
  <a>C.F. {{ cf }}</a>
    {%- endif %}

in metadata.yaml:

- name: codice_fiscale
    type: input
    attributes:
     label: Codice Fiscale
     description:  |
        Se includere il Codice Fiscale del registrante.