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.

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


$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
$options['filter'] = true;

// 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;


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:

['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:

['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:

['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