Results 1 to 10 of 10

Thread: [solved] Custom images for News Articles

  1. #1
    User
    Join Date
    03-28-13.
    Location
    Bietigheim-Bissingen
    Posts
    55

    Default [solved] Custom images for News Articles

    Hi.
    Q1: I would need an option to add 3 different images for each news article (1 for a big slider, 1 for a large overview and 1 for a small overview). What would be the best way to add these fields in (and only in) the edit news article section?


    Q2: How can I make a newslist which returns the latest news from 3 different news archive?

    Thanks!
    Last edited by zoltanseer; 08/11/2014 at 16:19. Reason: Solved

  2. #2

    Default

    Hi :-)

    Q1 : You can create an override of the tl_news DCA and create your 3 fields. If you need more explanatiions, I'll give you an exemple.

    Q2 : If you don't use featured option in your website, you can use it to do what you want.

    Steps :
    Create your module "NewsList"
    Check the cases of your 3 news archives
    Select the option Only Featured News in the field "News featured"
    It allows you to control exactly the news who will be showed in your Frontend.

    The other solution is to create 3 modules Newslist with one news archive chosen in each module and limit the number of items at 3.
    Then you activate the 3 modules in your Frontend.

    I hope it'll help you :-)

  3. #3
    User
    Join Date
    03-28-13.
    Location
    Bietigheim-Bissingen
    Posts
    55

    Default

    Hi Lupus!
    Thanks for you quick answer. Everything looks ok, only one question How/where should I create the file which overrides the tl_news?

  4. #4

    Default

    - Go into system/modules
    - Create a folder with the name you want (Logically, his name should be newsExtended)
    - Create classic folders (dca / languages + your language inside languages) -- The folder config isn't necessary for this kind on extension
    - Create the file "tl_news.php" in dca folder
    - You will need to override the subpalette called "addImage" (I think it's in this way you want to do it) and create some fields.

    To override the palettes, just use str_replace :
    PHP Code:
    $GLOBALS['TL_DCA']['tl_news']['subpalettes']['addImage'] = str_replace(',floating',',floating,field1,field2',$GLOBALS['TL_DCA']['tl_news']['subpalettes']['addImage']); 
    It will add your fields "field1" and "field2" when you check the checkbox "addImage".


    To add fields, just create it in the way you create fields of a module :
    PHP Code:
    $GLOBALS['TL_DCA']['tl_news']['fields']['field1'] = array(
         
    'label'                   => &$GLOBALS['TL_LANG']['tl_news']['field1'],
         
    'exclude'                 => true,
         
    'inputType'               => 'fileTree',
         
    'eval'                    => array('filesOnly'=>true'extensions'=>Config::get('validImageTypes'), 'fieldType'=>'radio''mandatory'=>true),
         
    'sql'                     => "binary(16) NULL"
    ); 
    Go to your install.php to add the fields to the database

    Finally, optionnal thing but it's better to do it :
    - Create the file "tl_news.xlf " in "languages/**YourLanguage**/ folder created previously
    - Add your label


    You can override a DCA on the way you want now !
    If you have questions on a specific point, or if you want more details, you can ask ;-)

  5. #5
    User
    Join Date
    03-28-13.
    Location
    Bietigheim-Bissingen
    Posts
    55

    Default

    Wonderful, beautiful.
    Thank you

  6. #6
    User
    Join Date
    03-28-13.
    Location
    Bietigheim-Bissingen
    Posts
    55

    Default

    Hi Lupus,

    sorry, I think I have another question. Until this point, everything is working. The problem is in the frontend I don't get back the path for my new images, rather the binary data. In the ModuleNews's parseArticle() method is where it changes the return value of the singleSRC to the image path. So I think I must write this for my new images, too. And now my question: should I override the whole parseArticle() method or is there some other solution for this?

    Thanks!
    Last edited by zoltanseer; 08/11/2014 at 17:03. Reason: typo

  7. #7

    Default

    This is the way to do it. But you maybe can do this faster by using directement the Model in a new template
    It's a little dirty, but it will work x)

    PHP Code:
    $path = \FilesModel::findByUuid($yourimagebinary)->path
    You can use after Image class to create the perfect image for your template
    http://api.contao.org/classes/Contao.Image.html

  8. #8
    User
    Join Date
    03-28-13.
    Location
    Bietigheim-Bissingen
    Posts
    55

    Thank you!

  9. #9
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    You can use the Extension-Creator in BE to create the skeleton of your new extension.

    Take a look at other core modules to find out how image fields with one or more images are made.

    You only need *.xlf language files if you like to do the translations with transifex. Else you can simply use a PHP file. Take a look at you server at /system/cache/language/en/ to find out how to code them.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  10. #10

    Default

    I forgot there is a creator of modules x)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •