MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

How to Customize Joomla Extensions Using Override?

Published on 25 June 15
1774
0
2
How to Customize Joomla Extensions Using Override? - Image 1

Joomla is undoubtedly the best CMS platform to get started your website on. It has some incredible features and functionalities that will help you give out an experience of a lifetime to the users. But, there are some frustrating moments you might experience on this platform. For one, some of the extensions may not give out the experience or output you are demanding. Instead of customizing the core, as you might have done in certain cases, you can now override the extensions, and introduce the functionalities you need.

Before understanding how override is created, you will need to understand what an override is. It is basically a copy of the extension layout file which is a part of your Joomla extension directory. Once you have that copy in hand, you can easily customize it and introduce the changes that you want to view.

Now, let's understand how to create override that will help you customize the particular functionality or feature.

Identify the Component
What is it that you wish to customize? Identify the portion that requires to be changed so that you get the output that matches your need. Once the component is identified, you will be able to locate the file that you need to override.

Let's say you want to change the position of the article title; instead of having it before the article, you want to shift it to the bottom of the article. You will first need to identify the component. Login to your admin panel, and visit the menu item of that particular page. In the menu item, you will find a URL that describes the component for you.

index.php?option=com_content&view=category&layout=blog&id=9 (This is the link)

Let's understand this link

File index.php
This is the entry point; it is a common path for all components on this CMS platform

Component option=com_content
It is the com_content that manages both categories as well as the content being posted to Joomla articles. This is an important part of the link

View: view=category
From this you will know that content component is using the view to offer the category

Layout: layout=blog
The category is presented in here by using the blog layout. If the layout is absent, as demanded here, then the default layout is used

Item: id=9
This refers to the category id represented by number 9. While this would help you understand Joomla database structure, it is hardly relevant to the override concept, you are trying to understand here.

Identify the File
Once, you have identified the component, your next task is to identify the file that you need to override in here. Whether, it is a component, view or layout, your file will be located in the PHP file in a particular structure. You will need to understand the structure, before you are able to locate the file.

Your com_content folder is located within the folder components, which further holds the category folder. The tmpl folder is located within the category folder, which holds the layout folder in the blog.php file. This is the file you need, to override and customize the component.

The Layout
The layout is not always a view file. In some cases, it is a composite view- wherein it has a main file for the blog, and individual files for the different parts within the blog. This particular layout is flooded with files located within the tmpl file. You will need to modify individual article's layout from within the blog, which means you need to understand PHP coding.

<div class=items=leading>
<?php foreach ($this->lead_items as &$item) : ?>
<div class="leading-<?php echo $leadingcount; ?><? php echo $item->state==0
? ' system-unpublished' : null; ?>">
<?php
$this->item=&$item;
echo $this ->loadtemplate ('item');
?>
</div>
<div class = "clearfix"></div>
<?php
$leadingcount++;
?>
<?php endforreach; ?>
</div><!âend items-leading ->
<div class ="clearfix"></div>
<?php endif; ?>
<?php
$introcount = (count ($this->intro_items));
$counter=0;

With this code, you can ensure that every time you want to modify blog.php file, the php file will use the echo $this ->loadtemplate ('item') code so that the file is presented for customization

Overriding the File
In the earlier steps, you have identified the file that you wish to override. So, let's start out with overriding. You will need to perform some echo tests, if you want to confirm if this is the file or not. Once confirmed, copy the file to the template; you can use HTML folder, and the existing component structure to perform the copy.

The file you need to copy here would be

html/com_content/category/blog_item.php

The file copied, is the override file that you will need to use in order to introduce the change that you had started out with initially. Joomla would be happy to accommodate the changes made to this file instead of the original core file.

Introducing the Changes
If you are planning on introducing the changes, then you need to have some experience in coding using PHP. A simple logic and some induction into HTML can help you achieve some of the basic changes

<?php
/**
*@package joomla.site
*@subpackage com_content
*/
defined ('JEXEC) or die;
// Create a shortcut for params
$params = &$this -> item-> params;
$images = json_decode($this->item->images);
$canEdit = $this->item->params->get ('access-edit');
jHtml:: addIncludePath(JPATH_COMPONENT.'/helpers/html');
$info = $this->item->params->get ('info_block_position',0);
jHtml:: _('behavior,tooltip');
jHtml :: _('behavior.framework');
?>
<?php if ($params->get('show_title') ll $this->item->state ==0ll ($params->get ('show_author') && !empty($this->item->author ))) : ?>
<div class="page-header">
<?php if ($params->get('show_title')) :?>
<h2>
<?php if ($params->get('link_titles') && $params->get ('access-view'))
:?>
<a href="<?php echo JRoute ::_(ContentHelperRoute :: getArticleRoute ($this->slug, $this->item->catid)); ?>"> <?php echo $
<?php else :?>
</h2>
<?php endif; ?>
<?php if ($this->item->state ==0):?>
<span class="label labe-warning"><?php echo JTest ::_ ('JUNPUBLISHED'); ?>
</span>
<?php endif; ?>
<?php if ($params->get('show_print_icon') ll params->get ('show_email_icon') ll $canEdit) :?>
<div class="btn-group pull-right"> <a class= "btn dropdown-toggle" data-toggle="dropdown" href="#" roles="button"> <span class="icon-con"> </span>

Now, your main aim is to move the title below the article. Here's the code that you should be using for this purpose

else :
echo JTest :: _ ('COM_CONTENT_READ_MORE');
echo JHtml :: _ ('string-truncate', ($this->item->title), $params->get('readmore_limit'));
endif; ?>
</a></p>
<?php endif; ?>
<?php if ($params->get ('show_title')) :?>
<h2>
<?php if ($params->get ('link_titles') && $params->get('access-view'))
:?>
<A href = "<?php echo JRoute :: _(ContentHelperRoute :: getArticleRoute
($this->item->slug, $this->catid)); ?>"> <?php echo $ this ->escapte ($this->item->title); ?></a>
<?php else :?>
<? php echo $this ->escapte ($this->item->title); ?>
<?php endif; ?>
</h2>
<?php endif; ?>
<?php echo $this->?item->event->afterdisplaycontent;?>

With this code added, your title will be displayed at the bottom of the site.
































































































































How to Customize Joomla Extensions Using Override? - Image 1

Joomla is undoubtedly the best CMS platform to get started your website on. It has some incredible features and functionalities that will help you give out an experience of a lifetime to the users. But, there are some frustrating moments you might experience on this platform. For one, some of the extensions may not give out the experience or output you are demanding. Instead of customizing the core, as you might have done in certain cases, you can now override the extensions, and introduce the functionalities you need.

Before understanding how override is created, you will need to understand what an override is. It is basically a copy of the extension layout file which is a part of your Joomla extension directory. Once you have that copy in hand, you can easily customize it and introduce the changes that you want to view.

Now, let's understand how to create override that will help you customize the particular functionality or feature.

Identify the Component
What is it that you wish to customize? Identify the portion that requires to be changed so that you get the output that matches your need. Once the component is identified, you will be able to locate the file that you need to override.

Let's say you want to change the position of the article title; instead of having it before the article, you want to shift it to the bottom of the article. You will first need to identify the component. Login to your admin panel, and visit the menu item of that particular page. In the menu item, you will find a URL that describes the component for you.

index.php?option=com_content&view=category&layout=blog&id=9 (This is the link)

Let's understand this link

File index.php
This is the entry point; it is a common path for all components on this CMS platform

Component option=com_content
It is the com_content that manages both categories as well as the content being posted to Joomla articles. This is an important part of the link

View: view=category
From this you will know that content component is using the view to offer the category

Layout: layout=blog
The category is presented in here by using the blog layout. If the layout is absent, as demanded here, then the default layout is used

Item: id=9
This refers to the category id represented by number 9. While this would help you understand Joomla database structure, it is hardly relevant to the override concept, you are trying to understand here.

Identify the File
Once, you have identified the component, your next task is to identify the file that you need to override in here. Whether, it is a component, view or layout, your file will be located in the PHP file in a particular structure. You will need to understand the structure, before you are able to locate the file.

Your com_content folder is located within the folder components, which further holds the category folder. The tmpl folder is located within the category folder, which holds the layout folder in the blog.php file. This is the file you need, to override and customize the component.

The Layout
The layout is not always a view file. In some cases, it is a composite view- wherein it has a main file for the blog, and individual files for the different parts within the blog. This particular layout is flooded with files located within the tmpl file. You will need to modify individual article's layout from within the blog, which means you need to understand PHP coding.

This blog is listed under Open Source and Development & Implementations Community

Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
You may also be interested in
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top