Adding extra image field to any DCA say tl_article
I have added a new field for article teaser Image like below in my custom module-> MyMod/dca/tl_article:
Code:
/* article teaser image */
$GLOBALS['TL_DCA']['tl_article']['fields']['atImage'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['atImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array('filesOnly'=>true, 'fieldType'=>'radio', 'tl_class'=>'clr'),
'sql' => "varchar(255) NOT NULL default ''"
);
// Augment the pallette
$GLOBALS['TL_DCA']['tl_article']['palettes']['default'] = str_replace('teaser;', 'teaser, atImage;', $GLOBALS['TL_DCA']['tl_article']['palettes']['default']);
In the template mod_artcle I wanted to out put this image. But doing <?php echo $this->atImage; ?> gives only the ID of an Image.
At the moment I am doing like:
Code:
<?php
$objFile = \FilesModel::findByPk($this->atImage);
echo $objFile->path;
?>
inside the template (mod_article), which I am not satisfied. I think there is a better way of setting up template variables with real image path. Can some one suggest please.
Re: Adding extra image field to any DCA say tl_article
That's the correct way to do it. If you would like to resize an image, then you would need to use
Code:
<?php \Image::get($objFile->path, 100, 100, 'center_center'); ?>
You would be able to deliver the path to the template only if you override the ModuleArticle class.
Re: Adding extra image field to any DCA say tl_article
Thank your for the answer, and your blog helped me a lot too.
At the moment the correct answer is not so satisfying because I've to put lots of php code in Template file. So I think overriding the Module class might be a better option. Can you tell me a best practice how to override a core class.