2 - List default template

The next step is to prepare the template

/ administrator / components / com_dealer / views / cars / tmpl / default.php

The default list template, like the view main file, will be pretty much the same for every list view, as the true main differences are made by the content, not by the view management structure. Probably you will copy and paste this file too, as is, for every list default.php file.


<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen''select');
JHtml::_('bootstrap.popover');
JHTML::_('behavior.modal');

$this->user      JFactory::getUser();
$this->listOrder $this->escape($this->state->get('list.ordering'));
$this->listDirn  $this->escape($this->state->get('list.direction'));
$this->saveOrder $this->listOrder == 'a.ordering';


$options = array();
$options['this'] = $this;

// USE TEMPLATE O LAYOUT ///////////////////////////
//
// enable template to use template view's templates:
//      default_header.php
//      default_body.php
//      default_foot.php
//
// layouts will be used otherwise searching for them in
// administrator/components/com_dealer/layouts/cars/
//      header.php
//      body.php
//      foot.php
$options['template'] = true;

// USE FILTER FORM ////////////////////////////////
//
// enable filter to include filter form
// IT REQUIRES ITS FILTER FORM TO BE IN MODELS/FORMS FOLDER
$options['filter'] = true;

// ORDERING TABLE ROWS
//
// we have to identify each group in order to get a different order for each of them
// to do it, we set the group ID in the table tag
$options['ordering'] = array();
$options['ordering']['orderingGroupId'] = Bp::getView().'List';
// ordering instructions
$options['listOrder'] = $this->listOrder;
$options['listDirn'] = $this->listDirn;

$this->options $options;

echo 
BpForm::adminList($this->sidebar$this->items$this->pagination$options);


The dirty work is still made by the class BpForm, through the method adminList().

Applying the same philosophy we used for the toolbar buttons, we pass an array of instructions to the method to customize the list form. The script is pretty self-explanatory so we are not going to explain the same process twice. 

For the sake of clarity we added tons of extra comments but obviously you can get rid of them in your files, even if we suggest to keep them handy.

And now?
All you have to do is to prepare your head, body and foot files, your true core component.

Congratulation! You just stopped to waste your time over what the CMS can do for you!

Extra contents

Sometimes you may want to add extra contents, like an alert message to the list header.

Expand the options array by adding an alert instruction:


<?php
$options
['alert'] = true;
$options['alert']['text'] = "COM_DEALER_CARS_LIST_ALERT_TEXT";
// you may want to prepend an icon to the text
$options['alert']['icon'] = "your icon class";          // default is "fa fa-info-circle"
//you may want to add a class to the message
$options['alert']['class'] = "alert alert-warning";     // default is "alert alert-info"


Other times you may want to add extra header contents.
Let's say you may want to display totals in the header, like total used cars, total new cars, total cars repairing and so on.

All you have to do, as you can guess, is to pass the instruction to the method:


<?php
$options
['customHeader'] = 'my_extra_header_file.php';
// if you set to use template
// the script will search for "default_my_extra_header_file.php"
// otherwise will search for layouts "my_extra_header_file.php"
// in administrator/components/com_dealer/layouts/cars/ folder


You may want to add a custom footer. Guess what? You pass the instruction to the method by expanding the options array:


<?php
$options
['customFooter'] = 'my_extra_footer_file.php';
// if you set to use template
// the script will search for "default_my_extra_footer_file.php"
// otherwise will search for layouts "my_extra_footer_file.php"
// in administrator/components/com_dealer/layouts/cars/ folder