Themes: fields mismatch between theme definition and invoice

Using Manager v 17.10.26

Either I’m missing some key information or the varialbe “fields” is messed up between the theme and the actual invoice.
If there’s another way to access invoice number and date OTHER than “fields”, please let me know, otherwise read on.

Loosely similar to @tomas question I wanted to access invoice date and number variables individually so that I could place them different areas of the invoice.

First attempt (simplified):

   <div>Invoice  # {{ fields[0].text }}</div>   <div>Date: {{ fields[1].text }}</div>

This looks perfect in the theme preview, however the fields’ indeces CHANGE in the actual invoices to which the theme is applied.
Invoice # [shows invoice date] Date: [ shows invoice due date]

To work around the percieved defect, I used an “if” for each:
e.g.

<div>Invoice # 
{% for field in fields %}
   {% if field.label == 'Reference' %}
      {{ field.text }}
   {% endif %}
{% endfor %}</div>

Again, looked GREAT in the theme preview, but doesn’t work in the actual invoices (shows blank).

After a little debugging, I found the LABELs are different between the actual invoice and the theme, so I resolved it with:

<div>Invoice # 
{% for field in fields %}
   {% if field.label == 'Invoice number' %}
      {{ field.text }}
   {% endif %}
{% endfor %}</div>
  1. if the invoice reference, date and due date are available in other variables, please let me know
  2. if not, would it be feasible to make them more accessible like “recipient” and “business”?
    e.g.
    invoice.reference
    invoice.date
    invoice.dueDate

…or even an associative array (hash)?

    fields['reference']
    filesd['date']
    fields['dueDate']
  1. Lastly, could the ‘text’ fields be at least made the same between invoice and theme?

Thanks for reading this far.

Ron

from which version did you update? if you updated from a very old version it is possible the variables would have changed accommodating the various changes Manager has at present.

what are you referring by theme here? the official themes are available at this link https://www.manager.io/themes/

this is the best way to access the variables with the actual labels they appear on the form.

Thanks for the quick response.

I upgraded from 17.7, but even when I create a new theme and a new invoice, the labels still differ between theme and invoice - this makes it tedious to customize a theme when one has to flip back and forth to an invoice to verify it that it works.

I am customizing an “official” theme - is that not the best practice?

Looping through an array looking for something might be the “only way” in a Manager theme, but I would argue that it’s not the “best” way. Speaking from 30 yrs as a software devloper. I expect consistency, in that there would be an “invoice” object (as I suggested) similar to the “recipient” object that provides access to its associated data by name instead of index.

Agreed on this.

However, it is what it is for now :slight_smile: If you get stuck with another variable or two, let us know here. Yet another software developer :wink: happy to help out.

IIRC, we can do just {{ fields }} and it’ll dump the whole array. It’s a quick way of finding out what you have to play with.

I would recommend switching back and forth between the editor and some real-life invoices, rather than using the preview. The preview only caters for one possible scenario.

Thanks for the tip. I found the Liquid for Designers webpage and now I’m having fun making ridiculous customizations to my theme. I should really get back to work :frowning:

1 Like