Catalog Steuern der Kommentarfunktion abhaengig vom Wert eines Catalog feldes

Aus Contao Community Documentation


Problem

Die Kommentare und Kommentarfunktion soll nur angezeigt werden, wenn das Feld eines Items einen bestimmten Wert hat.

Der Inhalt des Readers wird in mod_catalogreader.tpl (View) bzw. die Detailinhalte in catalog_full.tpl (Partial) erstellt. Im mod_catalogreader.tpl sind die einzelnen Felder jedoch nicht als Variablen vorhanden.

Wie kann man Variablen zwischen den Templates übergeben?

Mögliche Lösung eines Contao Neulings

Speicherung der Variablen in Globals in catalog_full.tpl:

<?php if (count($this->entries)): ?>
	<div class="layout_full">
	<?php foreach ($this->entries as $entry): ?>
		<div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''; ?>">
		<?php if($entry['linkEdit']): ?><?php echo $entry['linkEdit']; ?><?php endif; ?>
 
		<?php //save state of field Typ for using it in template mod_catalogreader.tpl
		 $GLOBALS['Type_of_Item'] = $entry['data']['Typ']['value'];?>
....

Prüfen des Wertes in mod_catalogreader.tpl

...
<?php if ($this->allowComments and $GLOBALS['Type_of_Item']=='Wert1'): ?>
...
Ansichten
Meine Werkzeuge

Contao Community Documentation

Nein, der Hangout ist noch nicht vorbei, wir schweigen nur. Es heisst ja auch hangout und nicht bryll out.

Christian Schiffler
Navigation
Verstehen
Verwenden
Entwickeln
Verschiedenes
Werkzeuge