jeffchannell.com

Custom Component Views in Joomla! 1.5

Posted in Joomla!
2009-04-30 04:12:32 +0000 UTC

Sometimes, the default Joomla! layouts for components just don't fit with the design of the template. Fortunately, Joomla! allows for custom component templates, without the need to hack core files. As an example, let's create a custom template for com_search.

The first thing that needs done is to create the folder structure that Joomla! expects. In the /templates/<template name>/ folder, create a new folder named 'html', and within that folder another folder named 'com_search', and within that another named 'search'. Linux users with shell access can create this quite easily (assuming the current working directory is the root of the Joomla! install):

$ mkdir -p templates/<template name>/html/com_search/search

Now that the folder structure is in place, the best launchpad for starting a custom component template is the original core. This way, all the features of the particular component can be integrated using the original PHP code. The core component files, in the case of com_search, reside in components/com_search/views/search/tmpl/.

In a generic sense, Joomla! expects the folder structure of the custom component templates to have the following basic structure:

templates/<template name>/html/<com_component>/<component view>/<view file>.php

To continue with the example of com_search, the relevant files to copy are default_form.php, default_results.php and default_error.php. Once these files are copied to the template folder, they can be manipulated freely. Joomla! will render the component in the manner specified by the template without the need to change any core system files.