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.
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 :
On the basis of your menu ID (ItemID) you can include a different
index<x>.php
in your mainindex.php
, like so: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:
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:
Then you need to add that to the BODY tag as an ID:
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.