Custom template: mod_newslist.tpl
Hi,
Does anyone know a way to have different versions of the mod_newslist template?
I have several news archives, and for one of them, I need to modify the mod_newslist template. But I haven't found a way to choose a custom template for a certain news archive.
I do know that I can choose templates within the module (news_full.tpl, news_simple.tpl...) but in this case, I need to have two versions of the mod_newslist template.
Any clues?
Re: Custom template: mod_newslist.tpl
I don't think you can have multiple versions of a mod_* template. I would modify each mod_newslist instance through a unique css id/class.
Re: Custom template: mod_newslist.tpl
Re: Custom template: mod_newslist.tpl
Hi Ola,
I actually did this but for the mod_eventlist.tpl but it should work the same way with the mod_newslist. I had to create a custom extension to do the trick. Unfortunatly I dont remember exactly how I did it but I will take a look at the files altered when I get back at the office tomorrow and hopefully I´ll be able to give a more detailed description on how i solved it. But I basically made a whole new eventlist to choose from in back-end. I copied all code that makes up the eventlist and changed the name to "my_eventlist" so now i have two different eventlist to choose from... this probably doesn´t make any sense :) so as I said I´ll get back when I´ve got at chance to re-cap how I did it.
Re: Custom template: mod_newslist.tpl
Hello again!
Ok, so now I´m back at the office and have taken a look at exactly how I did to solve this for the event list. But the same steps would probably apply to the news list.
First make the proper folder structure for your new extension and create the necessary files
My_extension
-> config
-> config.php
-> dca
->tl_module.php
-> languages
->en
->sv
->modules.php
-> et cetra...
->templates
-> mod_eventlist_mylist.php
->ModuleEventlistMyList.php
The file ModuleEventlistMyList.php which is place directly under My_extension is a copy of the orignal ModuleEventlist
with these changes
Original:
Code:
class ModuleEventlist extends Events
{
/**
* Current date object
* @var integer
*/
protected $Date;
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_eventlist';
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### EVENT LIST ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'typolight/main.php?do=modules&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->cal_calendar = $this->sortOutProtected(deserialize($this->cal_calendar, true));
// Return if there are no calendars
if (!is_array($this->cal_calendar) || count($this->cal_calendar) < 1)
{
return '';
}
return parent::generate();
}
And here is the modified version:
Code:
class ModuleEventlistMyList extends Events
{
/**
* Current date object
* @var integer
*/
protected $Date;
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_eventlist_mylist';
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### EVENT LIST MYLIST ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'typolight/main.php?do=modules&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->cal_calendar = $this->sortOutProtected(deserialize($this->cal_calendar, true));
// Return if there are no calendars
if (!is_array($this->cal_calendar) || count($this->cal_calendar) < 1)
{
return '';
}
return parent::generate();
}
What I did was that I changed the name of the function, and the name of the template file and the backend wildcard.
The config.php registers the new frontend module and looks like this:
Code:
array_insert($GLOBALS['FE_MOD'], 2, array
(
'events' => array
(
'eventlistmylist' => 'ModuleEventlistMylist'
)
));
The tl_module.php adds the new eventlist to the DCA and looks like this:
Code:
$GLOBALS['TL_DCA']['tl_module']['palettes']['eventlistmylist'] = '{title_legend},name,headline,type;{config_legend},cal_calendar,cal_noSpan,cal_format,cal_order,cal_limit,perPage;{template_legend:hide},cal_template,imgSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
And the languages file looks like this:
Code:
$GLOBALS['TL_LANG']['FMD']['eventlistmylist'] = array('Min händelselista', 'Denna modul listar alla händelse för en månad, en vecka eller en dag.');
And the mod_eventlist_mylist.tpl is just a copy of the original mod_eventlist.tpl whith the changes I wanted.
Hope this claryfies how i did work my way around to have a custom list
/Mike
Re: Custom template: mod_newslist.tpl
Wow, thanks Mike and everyone else! These different solutions will be good to have for future reference.
In my case, I solved the problem by adding some javascript code in the header that inserted the necessary html.
(I have made a custom photo/news slideshow, that needed some simple navigation buttons. Therefore I needed to count the number of newsitems, to add the correct number of buttons.)