Der Code kann am Ende des oberen PHP Teils eingefügt werden.
Das Echo dann im eigentlich HTML Bereich, wo die Ausgabe erfolgen soll.
Ankündigung
Einklappen
Keine Ankündigung bisher.
customelement_text_image_bar mit Bildunterschrift
Einklappen
X
-
Hallo Tim
Danke für den Hinweis. wie kann ich den Code:
hier ins customelement_text_image_bar.html5 einfügenCode:$file = \Contao\FilesModel::findByPk( $this->field('image')->value() ); $meta = array(); if( $file !== null ) { $tmp = \Contao\StringUtil::deserialize( $file->meta ); if( isset($tmp[ $GLOBALS['TL_LANGUAGE'] ]) ) { $meta = $tmp[ $GLOBALS['TL_LANGUAGE'] ]; } unset($tmp); } echo $meta['caption'];
Code:<?php // responsive images $objFile = \Contao\FilesModel::findByPk( $this->field('image')->value() ); if( $objFile !== null ) { $objPicture = \Contao\Picture::create($objFile->path,deserialize( $this->field('image')->option('size') ) ); $arrMediaQueries = array(); if( $objPicture !== null ) { $arrPicture = $objPicture->getTemplateData(); foreach($arrPicture['sources'] ?: array() as $data) { if( strlen($data['media']) < 1 ) { continue; } $arrMediaQueries[] = '@media '.$data['media'].' { .ce_text_image_bar_'.$this->id.' .res-image { background-image:url('.$data['src'].') !important; } }'; } } if( count($arrMediaQueries) > 0 ) { $GLOBALS['TL_HEAD'][] = '<style>'.implode("\n",$arrMediaQueries).'</style>'; } } ?> <div class="<?php echo $this->class; ?> ce_text_image_bar_<?php echo $this->id;?> <?php echo $this->field('schema')->value(); ?> <?php echo $this->field('bg_color')->value(); ?> <?php echo $this->field('color')->value(); ?> block<?php if($this->field('show_arrow')->value()): ?> show-arrow<?php endif; ?><?php if($this->field('mob_pos')->value()): ?> <?php echo $this->field('mob_pos')->value(); ?><?php endif; ?>"<?php echo $this->cssID; ?> style="<?php if($this->field('own_color')->value()): ?>background-color:<?php echo $this->field('own_color')->html(); ?><?php endif; ?><?php if ($this->style): ?><?php echo $this->style; ?><?php endif; ?>"> <div class="inside"> <div class="textbox"<?php if($this->field('height')->value()): ?> style="height:<?php echo $this->field('height')->value(); ?>px"<?php endif; ?>> <div class="text-table"> <div class="text-cell"> <?php if($this->field('subheadline')->value()): ?><div class="subheadline"><?php echo $this->field('subheadline')->value(); ?></div><?php endif; ?> <?php if($this->field('headline')->value()): ?><?php echo $this->field('headline')->html(); ?><?php endif; ?> <?php if($this->field('text')->value()): ?><?php echo $this->field('text')->html(); ?><?php endif; ?> <?php if($this->field('link')->value()): ?><div class="ce_hyperlink"><?php echo $this->field('link')->html(); ?></div><?php endif; ?> </div> </div> </div> <div class="imagebox res-image" style="background-image: url(<?php echo $this->field('image')->generate(); ?>);"> <?php if($this->field('show_arrow')->value()): ?><div class="arrow <?php echo $this->field('bg_color')->value(); ?>"<?php if($this->field('own_color')->value()): ?> style="background-color:<?php echo $this->field('own_color')->html(); ?>"<?php endif; ?>></div><?php endif; ?> </div> <div class="mobile_image"><?php echo $this->field('image')->html(); ?></div> </div> </div>
Einen Kommentar schreiben:
-
Das Bild kommt als CSS Hintergrundbild in das Element. Eine Bildunterschrift ist dafür erstmal nicht vorgesehen.
Um eine Bildunterschrift direkt auszulesen müsste in den Bild-Attribut-Einstellungen das Bildunterschriftfeld hinzugefügt werden. Dann kann man es im Template direkt auslesen.
https://forum.premium-contao-themes....late-variablen
$this->field('image')->option('caption');
Wenn man über die Meta-Daten gehen will (Bildunterschrift in Dateiverwaltung), muss man über ein FileModel gehen.
$file = \Contao\FilesModel::findByPk( $this->field('image')->value() );
$meta = array();
if( $file !== null )
{
$tmp = \Contao\StringUtil::deserialize( $file->meta );
if( isset($tmp[ $GLOBALS['TL_LANGUAGE'] ]) )
{
$meta = $tmp[ $GLOBALS['TL_LANGUAGE'] ];
}
unset($tmp);
}
echo $meta['caption'];
Das customelement_grid_gallery_image Template macht es oben vor.Zuletzt geändert von Tim; 29.03.2023, 07:20.
Einen Kommentar schreiben:
-
customelement_text_image_bar mit Bildunterschrift
Wie kann ich den Dateiverwaltung-Eintrag der Bildunterschrift in das customelement_text_image_bar.html5 einfügen?
Habe es mit <? echo $this->caption ?> versucht, weiss aber nicht wie einfügen.
Hat jemand eine Idee wie das gehen könnte?
Vielen Dank :-)
Stichworte: -

Einen Kommentar schreiben: