Print
Category: Tutorials
Hits: 6788
27Mar2023

Add your own information types in Latest News Enhanced Pro

Information
First published January 13, 2017
6788 hits -

It is possible to add custom information for each individual item in Latest News Enhanced Pro, on top of the detailed information you can already show.

In order to do that, we can take advantage of 2 of the hooks (events) available in the extension.

First, we need to be able to add the field type in the list of fields available for output and second, we need to set how the output will present itself for each item.

With this tutorial, you will be able to add:

For this tutorial, you need:

Information types
The additional information types

You can use the plugin plg_latestnewsenhanced_mydetails as-is, but its usage will be limited.

The plugin can easily be internationalized by adding your own language files (in this case, mydetails.xml will need to be updated accordingly) or by creating language overrides.

Step 1 Install the plugin (not on a production site). It will be found under plugins/latestnewsenhanced/

Step 2 Open the plugin file mydetails.php. The code is documented with key information.

Step 3 Go to the method onLatestNewsEnhancedPrepareDetailSelection. This is the code that will be called whenever the select box containing all the information types is created.

Step 4 Add the name of the type you want to see as information type to the array of information types.

$information_types[] = '[information type]';

Note The information type is made of [the plugin name]_[the type]. For instance : mydetails_title.

Step 5 Go to the method onLatestNewsEnhancedGetDetailData. This is the code that will be called whenever items are shown on the page. For parameter explanations, check the source code.

Step 6

LNEP 2.5+ Add the html code and data to the block that will be shown when selecting the information type. A classic output bloc will look like this:

if ($detail[0] == '[information type]') {
    $info_block = '<span class="detail detail_[information type]">';
    $info_block .= modLatestNewsEnhancedExtendedHelper::getPreData($detail[1], $detail[2], '[default icon]', $detail[3]);
    $info_block .= '<span class="detail_data">';
    $info_block .= '[content output]';
    $info_block .= '</span>';
    $info_block .= '</span>';
    return $info_block;
}

LNEP 4.6+ The output code is now placed into overridable layouts.
On plugin install, the sample layouts are moved to the Latest News Enhanced Pro extension (into /layouts/details). It is imperative that you place your new layouts there in order for them to be taken into account. You can override them in your template.

Layout files must follow the convention: lnep_detail_[information_type].php

Note For the list of icons you can use as default for your type, go to documentation/common-features/icon-picker-common.

Step 7 Save your code.

Step 8 Open the file en-GB.plg_latestnewsenhanced_mydetails.sys.ini.

Step 9 Add the key/value pair that corresponds to the information type that you have created. Follow the convention: PLG_LATESTNEWSENHANCED_[plugin name]_DETAIL_LABEL_[information type]

You will get the following output for this sample plugin:

Result

More information is available in the extension's documentation, under the Extend the extension section.