[teaserimages] Teaser-Bild eines bestimmten Artikels anzeigen

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • JaiBee
    Contao-Nutzer
    • 12.11.2010
    • 178

    #1

    [teaserimages] Teaser-Bild eines bestimmten Artikels anzeigen

    Hallo,

    wie lässt sich mit der Erweiterung teaserimages das zu einem bestimmten Artikel gehörende Teaser-Bild anzeigen? Also im Prinzip wie folgt: {{teaserimage::*}} (* = Artikel-ID).

    Konkret geht es darum, dass ich das Template der Erweiterung ce_article_list so anpassen möchte, dass auch das Teaser-Bild angezeigt wird, was derzeit leider nicht der Fall ist.

    $this->showTemplateVars() enthält im entsprechenden Artikel folgende Angaben zum Teaser-Bild:
    Code:
         [singleSRC] => <Bild-URL>
         [alt] => <Alt-Text>
         [size] => <Größe>
    An diese Angaben müsste ich also im Template von ce_article_list herankommen.

    Vielen Dank!

    Gruß JaiBee


    EDIT:
    Verstehe ich es richtig, dass in folgender Datei ArticleImage.php die Bildeigenschaften aus der Datenbank geholt und ins Template integriert werden? Denn damit müsste sich ja dann etwas machen lassen…
    PHP-Code:
    class ArticleImage extends Frontend
    {
        /**
         * Add image to template.
         *
         * @param $objTemplate template to add the image to
         * @param isCE if constructor is called from an content element template
         */
         public function __construct($objTemplate, $isCE = false) {
             // save article href
             $objTemplate->articleHref = $objTemplate->href;
         
             // connect to database and get image settings
             $this->import('Database');
             
             $objImage = $this->Database->prepare("SELECT addImage, singleSRC, alt, size, imagemargin, fullsize, caption, floating FROM tl_article WHERE id=?")
                             ->limit(1)
                             ->execute($isCE ? $objTemplate->article : $objTemplate->id);
             
             $arrImage = $objImage->fetchAssoc();
             // add image to template if necessary
             if($arrImage['addImage'])
             {
                 $this->addImageToTemplate($objTemplate, $arrImage);
             }
         }
    } 
    

    EDIT: ein blindes Huhn…
    PHP-Code:
             // connect to database and get image settings
             $this->import('Database');
    
             $objImage = $this->Database->prepare("SELECT addImage, singleSRC, alt, size, imagemargin, fullsize, caption, floating FROM tl_article WHERE id=53")
                             ->limit(1)
                             ->execute($isCE ? $this->article : $this->id);
    
             $arrImage = $objImage->fetchAssoc();
             // add image to template if necessary
             if($arrImage['addImage'])
             {
                 $this->addImageToTemplate($this, $arrImage);
             }
    
    
    echo "<pre>".$this->showTemplateVars()."</pre>"; 
    
    ergibt:
    Code:
        [imgSize] =>  width="150" height="226"
        [floatClass] =>  float_left
        [float] =>  float:left;
        [src] => system/html/xyz-af2c129e.jpg
        [addBefore] => 1
        [margin] =>
    Tadaa, das Teaser-Bild des Artikels 53
    Zuletzt geändert von JaiBee; 11.08.2011, 17:43. Grund: + ArticleImage.php
  • Tim G
    Contao-Urgestein
    • 13.02.2010
    • 2212

    #2
    Hi,
    schau mal ob dir das bereits hilft:



    Da hab ich das Template der ArticleList mal angepasst für sizta7.

    Ansonsten sind die Spaltennamen wie die vom normalen Artikelbild nur mit 'teaser_' davor.

    Grüße Tim
    http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.

    Kommentar

    • JaiBee
      Contao-Nutzer
      • 12.11.2010
      • 178

      #3
      Zitat von Tim G Beitrag anzeigen
      Hi,
      schau mal ob dir das bereits hilft:

      http://www.contao-community.de/showt...l=1#post133467
      Jetzt habe ich sogar 2 funktionierende Lösungen, wobei deine, Tim, wohl etwas besser ist. Vielen Dank dafür.

      Für alle, die hier eventuell mitlesen, der fertige Code:
      HTML-Code:
      <?php
      $this->import('Database');
      
      $id = $page['articles'][0]['id'];
      $objFields = $this->Database->prepare("SELECT * FROM tl_article WHERE id=?")
                      ->limit(1)
                      ->execute($id);
      if(!$objFields->numRows) return;
      $showTeaser = $objFields->showTeaser;
      $alt = $objFields->alt;                                         // Tim, das hat bei dir noch gefehlt ;-)
      $addImage = $objFields->addImage;
      $singleSRC = $objFields->singleSRC;
      $size = deserialize($objFields->size);
      $src = $this->getImage($singleSRC, $size[0], $size[1], $size[2]);
      $floating = $objFields->floating;
      $addBefore = $floating != 'below';
      $floatClass = ' float_' . $floating;
      $float = ' float:' . $floating . ';';
      $caption = $objFields->caption;
      ($objFields->imageUrl) ? $href = $objFields->imageUrl : $href = $article['url'];
      $fullsize = $objFields->fullsize;
      $margin = $this->generateMargin(deserialize($objFields->imagemargin), 'padding');
      ?>
      
      
      <?php if ($addImage): ?>
      <div class="image_container<?php echo $floatClass; ?>"<?php if ($margin || $float): ?> style="<?php echo trim($margin . $float); ?>"<?php endif; ?>>
      <?php if ($href): ?>
      <a href="<?php echo $href; ?>"<?php echo $attributes; ?> title="<?php echo $alt; ?>">
      <?php endif; ?>
      <img src="<?php echo $src; ?>"<?php echo $imgSize; ?> alt="<?php echo $alt; ?>" />
      <?php if ($href): ?>
      </a>
      <?php endif; ?>
      <?php if ($caption): ?>
      <div class="caption"><?php echo $caption; ?></div>
      <?php endif; ?>
      </div>
      <?php endif; ?>

      Und diese Variante würde auch funktionieren:
      HTML-Code:
      <?php
      	// connect to database and get image settings
      	$this->import('Database');
      
      	$id = $page['articles'][0]['id'];
      	$objImage = $this->Database->prepare("SELECT addImage, singleSRC, alt, size, imagemargin, fullsize, caption, floating FROM tl_article WHERE id=?")
      					->limit(1)
      					->execute($id);
      
      	$arrImage = $objImage->fetchAssoc();
      	// add image to template if necessary
      	if($arrImage['addImage'])
      	{
      		$this->addImageToTemplate($this, $arrImage);
      	}
      
      //	echo "<pre>".$this->showTemplateVars()."</pre>";
      ?>
      <img src="<?php echo $this->src; ?>" <?php echo $this->imgSize; ?> class="<?php echo $this->floatClass; ?>" style="<?php echo $this->float; ?> <?php echo $this->margin; ?>"> />
      Gruß

      Kommentar

      Lädt...