[SOLVED] Einfache if-Abfrage im Fusion

Wahrscheinlich bin ich zu (PHP-) Verkopft aber ch bekomme zu fusion kein Draht :confused:

Ich habe mal wieder ein super einfache und banale Bedienung und ich verstehe nicht wie es sich lösen löst. Leider finde ich auch keine gute Dokumentation zum Zweck beziehungsweise Verwendung von @context, @if etc.

Aber zu meiner Frage.

Ich habe zwei berechnete Werte. Das klappt alles soweit. Bei der Ausgabe is jedoch die richtete Wortwahl entscheidend

  • 1 Monat
  • 2 Monate
  • 1 Jahr
  • 2 Jahre
  • 1 Jahr, 3 Monate
  • 2 Jahre, 1 Monat

in PHP wäre das ein sauberer 5-Zeiler. bei Fusion stehe ich wie der Ochse vor dem Berg. Ich bin für jede Hilfe. Sowohl bei meinem Problem, als auch Dokumentation :wink:

Hallo Tobias,

es kommt etwas auf den Anwendungsfall an, aber du kannst auf jeden Fall etwas machen wie folgendes:

variable = ${this.years + (this.years > 1) ? (' Jahre') : (' Jahr')}

Entweder fügst du die Monate dann noch inline an, oder du nutzt einen processor:

variable.@process.addMonths = ${value + ', ' + this.months + (this.months > 1) ? (' Monate') : (' Monat')}
variable.@process.addMonths.@if.condition = ${this.months && this.months > 0}

Dann werden die Monte nur appended, wenn relevant und in Variable gesetzt.

Versuch es doch einfach mal. Wenn du nicht weiter kommst, poste gerne mal dein Fusion. Dann können wir bestimmt drüber schauen :slight_smile:

Viel Erfolg!

Nikals

Hallo Niklas,

danke für die Schnelle Antwort. Ich habe jetzt ein wenig rumgespielt und verstehe es leider immer noch nicht ganz.

realisationDuration = ${Date.diff(q(node).property('startRealisationDate'), q(node).property('endRealisationDate'))}

duration = ${realisationDuration.y + (realisationDuration.y > 1) ? (' Jahre') : (' Jahr')}
noch
duration = ${this.realisationDuration.y + (this.realisationDuration.y > 1) ? (' Jahre') : (' Jahr')}

funktionieren . Auch nicht wenn ich realisationDuration.y vorher in eine Variable packen

year = ${realisationDuration.y}

Oh sorry, ich hab mich mit den Klammern etwas vertan. Probier mal folgendes:

	duration = ${this.realisationDuration.y + (this.realisationDuration.y > 1 ? ' Jahre' : ' Jahr')}

	duration.@process.addMonths = ${value + ', ' + this.realisationDuration.m + (this.realisationDuration.m > 1 ? ' Monate' : ' Monat')}
	duration.@process.addMonths.@if.condition = ${this.realisationDuration.m && this.realisationDuration.m > 0}

Sollte funktionieren, ich habs kurz probiert. Allerdings geht der Aufbau jetzt immer davon aus, dass mindestens 1 Jahr angezeigt wird. Vielleicht musst du also noch eine @if-Bedingung für die Jahreszahl bauen.

1 Like

Danke! Das hat geholfen. Jetzt kämpfe ich nur noch mit dem Update auf 5.0 Aber das ist ein anderes Thema!

1 Like