Add Window Target Option Per Banner In Joomla Banner Manager Component

Add Window Target Option Per Banner In Joomla Banner Manager Component

Sometimes a user wants to set a specific banner to open in a different target window than what the module setting dictates, without having to create a whole other module just to open a single banner from the same category in a new window, when the module target is set to parent. This is resolved with a selection field per banner creation. Of course the excellent JForm system allows that with simplicity. It will let a user override the module setting for any individual banner.

1. Create the folder which will contain all the files and give it a relative name

2. Create the primary function file within the folder and keep the name similar to the folder for simplicity

<?php defined('_JEXEC') or die();
* @package      plg_system_banner_window_target
* @copyright   Copyright (C) All rights reserved.
* @license      GNU General Public License version 2 or later; see

class plgSystemBanner_Window_Target extends JPlugin {

   public function onContentPrepareForm($form, $data) {
      // get the form field xml
      if( $form->getName() == 'com_banners.banner' ) {
         $form->loadFile('banner', false);


3. Create the installer XML file within the folder and give it the same name as the function file

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7.0" type="plugin" group="system" method="upgrade">
   <name>System - Banner Window Target</name>
   <copyright>All Rights Reserved.</copyright>
   <license>license GNU/GPLv3</license>
   <description>Add individual ad banner window target to override the module setting as needed</description>
      <filename plugin="banner_window_target">banner_window_target.php</filename>

4. Create a folder named form within the plugin folder and add the form control file which will be shown in the banner item edit under the image setting.

<?xml version="1.0" encoding="UTF-8"?>
<fields name="params">
   <fieldset name="image">
      <field name="wintarget" type="list" default="" label="Window Target">
         <option value="">Module Setting</option>
         <option value="0">Parent</option>
         <option value="1">New Window</option>
         <option value="2">Popup Window</option>

Be sure to add an empty index.html file to the folder or remove <filename>index.html</filename> from the installer .xml file.

5. Compress the parent folder with all the files as a .zip and install, enable, then go to Components > Banners > New. The select field will be above the Click URL field.

Create The Banner Module Template File

This is not an override. This will be selectable when publishing the banner module, under the Advanced tab, field labeled Layout. It outputs the same data as the core default, though the coding appears different, but it will include the window target condition to override the module setting per banner.

1. Create a php file and name it as desired eg: primarybanner.php. Add the following code and save.
2. Upload the file to modules/mod_banners/tmpl/
(you can optionally create an install.php file within the plugin and use JFile::copy() function to place the file)

<?php defined('_JEXEC') or die;

JLoader::register('BannerHelper', JPATH_ROOT . '/components/com_banners/helpers/banner.php');
$baseurl = JUri::base();

<div class="bannergroup<?php echo $moduleclass_sfx; ?>">

if( $headerText ) echo $headerText;

foreach( $list as $item ) :

//--------------[ Define Variables ]----------------------//
$link = JRoute::_('index.php?option=com_banners&task=click&id=' . $item->id);
$imageurl = $item->params->get('imageurl');

//set conditional variable values to default null
$imgwidth= $imgheight= $linkopen= $linkclose= $attrib='';

if( !is_null($item->params->get('width')) )
   $imgwidth = ' width="' . $item->params->get('width') . '"';
if( !is_null($item->params->get('height')) )
   $imgheight = ' height="' . $item->params->get('height') . '"';

$alt = $item->params->get('alt');
$alt = $alt ?: $item->name;
$alt = $alt ?: JText::_('MOD_BANNERS_BANNER');

/* get the module window target setting and override per banner setting
if value is not null
$target = $params->get('target', 1);
if( $item->params->get('wintarget') != '' )
   $target = $item->params->get('wintarget', '');


   <div class="banneritem">
      if( $item->type == 1 ) {
      // Text based banners
         echo str_replace(array('{CLICKURL}', '{NAME}'), array($link, $item->name), $item->custombannercode);
         // Image based banner
         if( BannerHelper::isImage($imageurl) ) {

            // setup link variations
            if( !empty($item->clickurl) ) {
               switch( $target ) {
                  // Open in new window
                  case 1: $attrib = 'target="_blank"';
                  // Open in a popup window
                  case 2: $attrib = '//the popup onclick function goes her. it is not allowed here so you will need to copy from original file';
               $linkopen = '<a href="'.$link.'" '.$attrib.' rel="noopener noreferrer" title="'.htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8').'">';
               $linkclose = '</a>';
            <?php //output the image and link if set
         echo $linkopen; ?>
         <img src="/<?php echo $baseurl . $imageurl;?>" alt="<?php echo $alt;?>" <?php echo $imgwidth . $imgheight; ?> />
      <?php echo $linkclose; ?>
         // output flash animated
         if( BannerHelper::isFlash($imageurl) ) { ?>
   // flash object coding goes here. not allowed here so you will need to copy from the original file
      <?php }
      } ?>
      <div class="clr"></div>
<?php endforeach; ?>

<?php if( $footerText ) { ?>
   <div class="bannerfooter">
      <?php echo $footerText; ?>
<?php } ?>