<![CDATA[ versuche per Bedingung "Kommentar" oder "Kommentare" auszugeben. - My Forums]]> https://forums.modx.com/thread/?thread=94479 <![CDATA[versuche per Bedingung "Kommentar" oder "Kommentare" auszugeben.]]> https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511705 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?]]>
andywizz Oct 01, 2014, 04:19 AM https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511705
<![CDATA[Re: versuche per Bedingung "Kommentar" oder "Kommentare" auszugeben.]]> https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511735 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!]]>
andywizz Oct 01, 2014, 10:07 AM https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511735
<![CDATA[Re: versuche per Bedingung "Kommentar" oder "Kommentare" auszugeben. (Best Answer)]]> https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511708
http://de.modx.com/forum/thread/6875/in-articles-mit-bedingung-kommentar-statt-kommentare#dis-post-37775]]>
Bruno17 Oct 01, 2014, 05:29 AM https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511708
<![CDATA[Re: versuche per Bedingung "Kommentar" oder "Kommentare" auszugeben.]]> https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511706
<?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');
]]>
ottogal Oct 01, 2014, 05:24 AM https://forums.modx.com/thread/94479/versuche-per-bedingung-kommentar-oder-kommentare-auszugeben#dis-post-511706