We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42652
    • 7 Posts
    Ich versuche über [[+comments_count]] die Anzahl der Kommentare aus dem Paket Articles zu ermitteln und dann entsprechend "Kommentar" oder "Kommentare" auszugeben.
    Hier mein bisheriger Versuch direkt über die MODX-REVO schreibweise:
    [[+comments_count:is=`1`:then=`Kommentar`:else=`Kommentare`]]

    Die Ausgabe bei einem Kommentar ist immer nur Kommentare obwohl [[+comments_count]] eins ausgibt.
    Die Verschachtelung habe ich zur Vereinfachung weggelassen.

    Normalerweise würde das, wie ich meine, so aussehen:
    [[+comments_enabled:is=`1`:then=`<a href="[[~[[*id]]]]#comments">([[+comments_count]])</a> [[+comments_count:is=`1`:then=`Kommentar`:else=`Kommentare`]]`]] bisher


    Mein Versuch die Abfrage in einem Snippet auszulagern:
    <?php
    $kommentar = '';

    if ([[+comments_count]]==1) {
    $kommentar = 'Kommentar';
    } elseif ([[+comments_count]]!=1) {
    $kommentar = 'Kommentare';
    }

    return $kommentar;

    Auch bei einem Kommentar ist das Ergebnis leider immer "Kommentare".
    Was mache ich falsch?

    This question has been answered by Bruno17. See the first response.

      • 22427
      • 793 Posts
      <?php
      $kommentar = '';
      if ([[+comments_count]]==1) {
      $kommentar = 'Kommentar';
      } elseif ([[+comments_count]]!=1) {
      $kommentar = 'Kommentare';
      }
      return $kommentar;
      
      Da fehlt zumindest ein Semikolon vor dem return. Außerdem würde reichen
      <?php
      $kommentar = '';
      if ([[+comments_count]]==1) {
      $kommentar = 'Kommentar';
      } else {
      $kommentar = 'Kommentare';
      }
      return $kommentar;
      
      oder einfacher
      <?php
      $komm = 'Kommentar';
      if ([[+comments_count]]>1) {
      $komm = $komm . 'e';
      };
      return $komm;
      

      Das eigentliche Problem liegt aber wohl darin, dass das Snippet-Tag
      [[+comments_count]] innerhalb des php-Codes nicht geparst wird. Hast du es mal uncached probiert?
      [[!+comments_count]]

      Ansonsten kannst du diesen Wert auch mithilfe einer API-Funktion ermitteln lassen:
      $modx->getPlaceholder('comments_count');
      [ed. note: ottogal last edited this post 9 years, 6 months ago.]
      • discuss.answer
        • 4172
        • 5,888 Posts
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 42652
          • 7 Posts
          Die Lösung stammt von Bruno in folgendem Thread:
          http://de.modx.com/forum/thread/6875/in-articles-mit-bedingung-kommentar-statt-kommentare

          Hier eine ähnliche Problematik für JOT auf MODX Evo:
          http://forums.modx.com/thread/?thread=43210&page=1

          Danke ottogal für die schnelle Antwort und die Mühe!