I am trying to access data from a text file in a template using the $field->toStructure() method. I´ve done this successfully in kirby2, now I fail in kirby3 (on my local MAMP) even when copying the code directly from the online-reference, I´m clueless.
The content in the text file looks like this:
uebergaenge:
-
abschnitt: Strecke 1
number: BÜ 1
name: Bahnhofstraße
zustand: offen
-
abschnitt: Strecke 1
number: BÜ 2
name: Andreaskreuz
zustand: offen
-
abschnitt: Strecke 2
number: BÜ 3
name: Kreuzstraße
zustand: geschlossen
-
abschnitt: Strecke 1
number: BÜ 4
name: Hägar der Schreckliche Straße
zustand: offen
I copied your text content into a file and the problem seems to be the tabs after the colons instead of a space character. When I then use the code, $uebergang->name() in fact doesn’t echo anything. Removing the tabs and replacing with spaces works, however.
The code as such is correct and should give you the correct results.
That is also the reason why your yaml array looks so funny, when it should look like this:
@texnixe Sublime is probably smart enough to convert the tab into spaces then. Because I literally copy pasted his code on a txt file and everything is working just fine on my end.
Thank you @texnixe. That was the problem. Like I said: I am feeling quite silly. But that´ll pass … Have a super nice day, you too @manuelmoreale and thanks to you too.
I have a similar problem. My structure field looks like this:
Meldungen:
-
anrede: Herr
akad_titel: Prof. Dr. med.
nachname: Heisel
-
anrede: Herr
akad_titel: Dr. med.
nachname: Kaiser
-
anrede: Herr
akad_titel: Dr.
nachname: Hirsch