contao / contao

Contao Open Source CMS
https://contao.org
GNU Lesser General Public License v3.0
350 stars 159 forks source link

$this->insert('picture_default', $picture); lacks LazyLoad attribute #2526

Closed Metis77 closed 3 years ago

Metis77 commented 3 years ago

tested in Contao 4.9

$objFile = (\Validator::isUuid($this->singleSRC)) 
        ? \FilesModel::findByUuid($this->singleSRC) 
        : \FilesModel::findByPath($this->singleSRC);        
$picture = \Picture::create($objFile->path,**imgSizeID**)->getTemplateData();         
$this->insert('picture_default', $picture);

if I include images like that (for example in a newslist template) the lazyload attribute from the imgSizes is ignored. Also the alt attribute stays empty.

If working with $this->insert('image', $this->arrData); the lazyload attribute is present. But this way, the image is wrapped in the newsreader reader link.

m-vo commented 3 years ago

First of all the Picture class is deprecated - do not use it anymore in your code. (If we're at it you should also stop using the globally namespaced class aliases instead of their 'real' location under the Contao namespace.)

The code in question simply does not handle meta data or additional attributes. For Contao 4.10 and up, you can use the image studio component. For older versions you might want to fiddle with Controller::addImageToTemplate().