Menu

#4927 Template and Layout overrides

Parent Category:
DPCalendar
Category:
Misc
Last Updated:
Allon Moritz, Friday, 03 September 2021 18:41
Created:
Wednesday, 21 June 2017 11:37
Hits:
7613

Introduction

Template overrides are a mighty tool for site integrators as they do allow you to adjust the markup of the views. This happens by copying the original files from the component, module or plugin to the templates html folder. It is a well known feature of Joomla and DPCalendar does 100% support it. So all views, modules and plugins are overridable within DPCalendar.

Joomla has covered that topic extensively in their docs:

There are also good tutorials available in the internet, so there is no point for us to copy them here again.

When to use an override?

The only thing we want to spread is that you should use overrides only when really needed. The problems are updates, as the override can become incompatible with the changes in the update, especially for new major versions. Please read this post about that topic in our blog. Most changes can be achieved by CSS in your templates custom.css file.

What to override?

Every view or module has a default.php file. This file is the entrance to the view and calls sublayouts which do render then different blocks. A sublayout has as prefix the name of the main layout, for example default_xxx.php. These sublayouts are often small and have one job to do, so we are isolating the logic. This methodology allows you to override only these sublayouts of the views while leaving the rest intact. Especially the default.php file should NOT be overridden, because when we add new features, we add them mostly in a new sublayout which gets called from the default.php file.

Lets take an example. The calendar view on /components/com_dpcalendar/views/calendar/tmpl has the following files:

  • default.php
  • default_heading.php
  • default_list.php
  • default_calendar.php
  • default_map.php
  • default_quickadd.php

For example this is the slimmed down content of the calendar view default.php:

<div class="com-dpcalendar-calendar">
    <?php echo $this->loadTemplate('heading'); ?>
    <?php echo $this->loadTemplate('list'); ?>
    <?php echo $this->loadTemplate('calendar'); ?>
    <?php echo $this->loadTemplate('map'); ?>
    <?php echo $this->loadTemplate('quickadd'); ?>
</div>

Every sublayout is called in the default.php through the loadTemplate function. So if you want to change the heading you don't need to make an override of all files, you can just do it with the file default_heading.php.

Comments (0)

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.