1

I am running Joomla and seeking you help for the following issue.

Lets say I have 3 layouts in my template and the layout files are named as...

index.php
index2.php
index3.php

I have 5 menu links say....

Link 1
Link 2
Link 3
Link 4
Link 5

What I am looking for is......

For Link 1, Link 4 and Link 5, I want Joomla to load the regular index.php but for Link 2 I want Joomla to load index2.php and similarly for Link 3 I want it to load index3.php.

What I mean is... How can we assign a different layouts to different menu IDs?

I know there is an inbuilt option to choose a different Template based on menu ID but I do not want to duplicate the template files just for this one function. Everything in my templates is the same just the change is in the layout depending on the Menu ID.

Kindly Help.

Vikram Rao
  • 1,068
  • 4
  • 24
  • 62

3 Answers3

1

I always use include_once or for security purpose require_once, from my point of view it is a better way of programming in the template process. - What do you think ? - Example I would do this way :

(isset($_GET['Itemid']))?$itemID=$_GET['Itemid']:"";
OU POUR LES PURISTES DE JOOMLA :
$itemID=JRequest::getInt('Itemid',0);

if($itemID == '57')
{
    require_once ("index1.php");
}
if($itemID == '58')
{
    require_once ("index2.php");
}
else
{
    // template code of index.php
}
jmayeux
  • 31
  • 5
1

Are you using a commercial template or something custom? You should be able to code your index.php so that the layout is determined by the modules loaded on the page. You then control what modules show up by the menu assignments in the module parameters. You can control the layout being displayed through CSS, Page Class Suffix, and the code on index.php.

Every module position in your template should be collapsible - meaning that if no modules are loaded to the position, it does not get added to the HTML. Use something like this:

<?php if ($this->countModules('left')) : ?>
    <jdoc:include type="modules" name="left" style="xhtml" />
<?php endif; ?>

You can also use a combination of the Page Class Suffix that you can set on the System Parameters of a menu item and CSS to control the layout of the page. I add the Page Class Suffix to the BODY tag of my templates so I can control every page individually.

First, you need to figure out which menu item you are on:

<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
?>

Then you need to add that to the BODY tag as an ID:

<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">

Now you can use module positions and CSS to control every page. You can achieve vastly different layouts without having to go back in and touch code.

Brent Friar
  • 10,588
  • 2
  • 20
  • 31
  • @ Brent Friar, I applied the code you described above. It works perfectly, thanks. But could you please tell me if I can use `` several times in the same document? I applied it now to to the div content but say for instance I want to use it on the "right column div"; could I just paste the code or would it conflict? I do not know anything about PHP but as an example with CSS I'm not able to use twice the same "id" on one page. (I'm new to Joomla and am using the beez installation with my own templates. Which works fine so far.) –  Jan 29 '11 at 20:18
  • You can use the $pageclass as many times as you want on the page as long as you follow a couple of simple rules - you can only use it as an ID once on the page, the best place for this will be the body or highest level container/wrapper. After that, you can use it as a class as many times as you want. You can also combine it with other selectors to create new IDs and classes. – Brent Friar Jan 30 '11 at 04:28
0

On the basis of your menu ID (ItemID) you can include a different index<x>.php in your main index.php, like so:

$itemID = $_GET['ItemID'];

if($itemID == '57')
{
    include index1.php
}
if($itemID == '58')
{
    include index2.php
}
else
{
    // template code of index.php
}
Pops
  • 30,199
  • 37
  • 136
  • 151
sushil bharwani
  • 29,685
  • 30
  • 94
  • 128
  • Hey Sushil Thanks for posting. What I am looking for is that by default it will display the index.php file but if an option is chosen (because here I don’t know how many itemIDs I'll assign a different template in future) in the template options panel then it must assign that page to that particular itemID. Example in the options I create a textbox where I can enter each param in one line like…. 57=index1 and 58=index2. Then it should do the job. So it should read like IF $itemID is defined then change layout otherwise regular one. Kindly help. – Vikram Rao Dec 24 '10 at 11:58
  • 1
    I think you need to do a little bit of tweaking in your code in C:\xampp\htdocs\code\administrator\components\com_templates. There you can provide a extra field asking for ur parameters and read these parameters in templates index.php file. And apply the template accordingly. The code should be pretty simple. – sushil bharwani Dec 24 '10 at 12:35