Data Templates from fireflyIII API

Hi,

I am trying to use the data templates to display a list of transactions of my project publicly. Unfortunately I don’t quite understand why I run into the following error when I want to call the individual values:

execute of template failed at <.attributes.transactions.date>: can’t evaluate field date in type interface {} 

donate_table.html

<div id="myList">
  <div class="fw-bold">Datum</div>
  <div class="fw-bold">Beschreibung</div>
  <div class="fw-bold">Kategorie</div>
  <div class="fw-bold">Betrag</div>
  <div>02.05.2023</div>
  <div>static</div>
  <div>Überweisung</div>
  <div>5,00 €</div>
  {{ range .Site.Data.transactions.data }}
    <div>{{ .attributes.created_at }}</div>
    <div>{{ .attributes.transactions.date }}</div>
    <div>{{ .attributes.created_at }}</div>
    <div>{{ .attributes.created_at }}</div>
  {{ end }}
</div>

data/transactions.json

{
  "data": [
    {
      "type": "transactions",
      "id": "316",
      "attributes": {
        "created_at": "2023-05-17T17:05:18+02:00",
        "updated_at": "2023-05-17T17:45:52+02:00",
        "user": "1",
        "group_title": null,
        "transactions": [
          {
            "user": "1",
            "transaction_journal_id": "317",
            "type": "deposit",
            "date": "2023-05-17T17:05:01+02:00",
            "order": 0,
            "currency_id": "1",
            "currency_code": "EUR",
            "currency_name": "Euro",
            "currency_symbol": "\u20ac",
            "currency_decimal_places": 2,
            "foreign_currency_id": null,
            "foreign_currency_code": null,
            "foreign_currency_symbol": null,
            "foreign_currency_decimal_places": 0,
            "amount": "25.000000000000",
            "foreign_amount": null,
            "description": "Spende",
            "source_id": "9",
            "source_name": "Spenden",
            "source_iban": "",
            "source_type": "Revenue account",
            "destination_id": "1",
            "destination_name": "BUNQ",
            "destination_iban": "NL67BUNQ2290486728",
            "destination_type": "Asset account",
            "budget_id": null,
            "budget_name": null,
            "category_id": "6",
            "category_name": "\u00dcberweisung",
            "bill_id": null,
            "bill_name": null,
            "reconciled": false,
            "notes": null,
            "tags": [],
            "internal_reference": null,
            "external_id": null,
            "original_source": "ff3-v6.0.9|api-v2.0.1",
            "recurrence_id": null,
            "recurrence_total": null,
            "recurrence_count": null,
            "bunq_payment_id": null,
            "external_url": null,
            "import_hash_v2": "5e90a43cf25492fe6b9db0931b81f1f8a275078247a5e5e3965181c6095ad82d",
            "sepa_cc": null,
            "sepa_ct_op": null,
            "sepa_ct_id": null,
            "sepa_db": null,
            "sepa_country": null,
            "sepa_ep": null,
            "sepa_ci": null,
            "sepa_batch_id": null,
            "interest_date": null,
            "book_date": null,
            "process_date": null,
            "due_date": null,
            "payment_date": null,
            "invoice_date": null,
            "longitude": null,
            "latitude": null,
            "zoom_level": null,
            "has_attachments": false
          }
        ]
      },
      "links": { "self": "https://firefly.rollenspiel.monster/api/v1/transactions/316", "0": { "rel": "self", "uri": "/transactions/316" } }
    },
    {
      "type": "transactions",
      "id": "315",
      "attributes": {
        "created_at": "2023-05-17T08:13:53+02:00",
        "updated_at": "2023-05-17T17:45:52+02:00",
        "user": "1",
        "group_title": null,
        "transactions": [
          {
            "user": "1",
            "transaction_journal_id": "316",
            "type": "withdrawal",
            "date": "2023-05-17T08:13:36+02:00",
            "order": 0,
            "currency_id": "1",
            "currency_code": "EUR",
            "currency_name": "Euro",
            "currency_symbol": "\u20ac",
            "currency_decimal_places": 2,
            "foreign_currency_id": null,
            "foreign_currency_code": null,
            "foreign_currency_symbol": null,
            "foreign_currency_decimal_places": 0,
            "amount": "200.750000000000",
            "foreign_amount": null,
            "description": "R0019213335",
            "source_id": "1",
            "source_name": "BUNQ",
            "source_iban": "NL67BUNQ2290486728",
            "source_type": "Asset account",
            "destination_id": "6",
            "destination_name": "Hetzner",
            "destination_iban": null,
            "destination_type": "Expense account",
            "budget_id": null,
            "budget_name": null,
            "category_id": "1",
            "category_name": "Server",
            "bill_id": "1",
            "bill_name": "Hetzner",
            "reconciled": false,
            "notes": null,
            "tags": [],
            "internal_reference": null,
            "external_id": null,
            "original_source": "ff3-v6.0.9|api-v2.0.1",
            "recurrence_id": null,
            "recurrence_total": null,
            "recurrence_count": null,
            "bunq_payment_id": null,
            "external_url": null,
            "import_hash_v2": "ea2f0d54de66161116c56703f98c5b5b0502029878800e7fb5421060ea260329",
            "sepa_cc": null,
            "sepa_ct_op": null,
            "sepa_ct_id": null,
            "sepa_db": null,
            "sepa_country": null,
            "sepa_ep": null,
            "sepa_ci": null,
            "sepa_batch_id": null,
            "interest_date": null,
            "book_date": null,
            "process_date": null,
            "due_date": null,
            "payment_date": null,
            "invoice_date": null,
            "longitude": null,
            "latitude": null,
            "zoom_level": null,
            "has_attachments": true
          }
        ]
      },
      "links": { "self": "https://firefly.rollenspiel.monster/api/v1/transactions/315", "0": { "rel": "self", "uri": "/transactions/315" } }
    }
  ],
  "meta": { "pagination": { "total": 16, "count": 5, "per_page": 5, "current_page": 1, "total_pages": 4 } },
  "links": {
    "self": "https://firefly.rollenspiel.monster/api/v1/accounts/1/transactions?start=2023-05-01&end=2023-05-31&limit=5&type=default&page=1",
    "first": "https://firefly.rollenspiel.monster/api/v1/accounts/1/transactions?start=2023-05-01&end=2023-05-31&limit=5&type=default&page=1",
    "next": "https://firefly.rollenspiel.monster/api/v1/accounts/1/transactions?start=2023-05-01&end=2023-05-31&limit=5&type=default&page=2",
    "last": "https://firefly.rollenspiel.monster/api/v1/accounts/1/transactions?start=2023-05-01&end=2023-05-31&limit=5&type=default&page=4"
  }
}

Ok with a second range I can solve it, is that the only way?

  {{ range .Site.Data.transactions.data }}
    {{ range .attributes.transactions }}
      <div>{{ .date | time.Format "02.01.2006" }}</div>
      <div>{{ .attributes.created_at }}</div>
      <div>{{ .attributes.created_at }}</div>
      <div>{{ .attributes.created_at }}</div>
    {{ end }}
  {{ end }}

data.attributes.transactions is an array, so you can either:

  • range over the array, OR
  • use the index function to target an element within the array
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.