Category Alternate Layout does not use defined layout

The support for Joomla 2.5 ended on December 31, 2014. Possible bugs in Joomla 2.5 will not be patched anymore. This forum has been closed. Please update your website to Joomla 3.x

Moderator: ooffick

Forum rules
Please use the official Bug Tracker to report a bug: https://issues.joomla.org
hoochicken
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Dec 20, 2011 8:17 am

Re: Category Alternate Layout does not use defined layout

Post by hoochicken » Tue Dec 20, 2011 9:49 am

Hi there,
I've found a workaround, that works quite well. For unfortunatly the solution of benny_71 (change of view.html.html) is very nice, it would not work:-( This is why I did the following:

See here the "overriding" template's default.php
(JPATH_BASE."/templates/templateName/html/com_member/category/default.php)
It is not really overriding the core-default.php
It ist more a "controller" or switch,
that switches between the template's alternative layout and the core default.
Thus, there is no need to touch the core default.php or the view.html.php or to really override it.
and you can use as many alternative layouts you want.

JPATH_BASE."/templates/templateName/html/com_member/category/default.php :

Code: Select all


<?php
/**Code for: 
JPATH_BASE."/templates/templateName/html/com_member/category/default.php : */

defined('_JEXEC') or die('Restricted access');

/*getting information about layout via get, see table #__menus*/
$get=JRequest::get('get');
$arr_layout=preg_split("/:/",$get['layout']); /*returns Array([0]=>templateName,[1]=>layoutName)*/ 

/*getting name of alternative layout and its path*/
$templateName=$arr_layout[0];
$layoutName=$arr_layout[1];
$layoutPath=JPATH_BASE."/templates/".$templateName."/html/com_member/category/".$layoutName.".php";

/*if alternative layout exists, use it; otherwise use core default;
 * To avoid a loop, alternative layout may not have the name of the overriding/existing default.php */
if ("default"!=$layoutName AND file_exists($layoutPath)) require $layoutPath;
else require(JPATH_BASE.'/components/com_member/views/category/tmpl/default.php');?>
Addendum: If you want to use an overriding default layout, too, the if-clause may look like this:

Code: Select all

<?php
if ("default"!=$layoutName AND file_exists($layoutPath)) require $layoutPath;
else require(JPATH_BASE.'/templates/'.$templateName.'/html/com_member/category/myDefault.php'); 
or as well

Code: Select all

<?php
if ("default"!=$layoutName AND file_exists($layoutPath)) : require $layoutPath;
else : ?>

<!--insert your default layout here; but the former solution is more beautiful -->

<?php 
endif; 

stefwilliams
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Jul 29, 2009 8:20 am

Re: Category Alternate Layout does not use defined layout

Post by stefwilliams » Fri Jan 13, 2012 3:46 pm

I have to say, this process of creating an XML file for menu items seems a bit convoluted, and unintuitive... Would it not be possible to have a drop-down for 'Alternative Layout' on the menu item config page - as with other over-rides?

In the meantime, can someone give a full run-down of exactly what xml file needs to be changed, what needs to be put in it, and where it needs to be saved?

I'm really confused :eek:

barback
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Feb 10, 2007 11:16 pm

Re: Category Alternate Layout does not use defined layout

Post by barback » Fri Jan 13, 2012 5:32 pm

stefwilliams wrote: In the meantime, can someone give a full run-down of exactly what xml file needs to be changed, what needs to be put in it, and where it needs to be saved?
When you look in the views/viewxxxx/tmpl folder of the component you are creating an alternate view for, you'll see both .php files and an .xml file.

If you are creating a template override -- to be used all the time by Joomla for this component. You only need to copy the .php file and put it in your template's html folder with a path like this:

your_template/html/com_xxxx/viewxxxx/default.php

viewxxxx might be "category" or something else.

If you are creating an alternative menu item type you'll take a COPY of that .php file and rename it
AND take a copy of the .xml file and rename it

These both go in your template's file as above.
your_template/html/com_xxxx/viewxxxx/mylayout.php
your_template/html/com_xxxx/viewxxxx/mylayout.xml

There are a few changes you need to make at the top of the xml file changing "default" to "mylayout" or whatever you are calling your custom layout.

When this .xml file exists in your template files, this will be an option in the menu item types list when you create a new menu item.

Hope this helps!

stefwilliams
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Jul 29, 2009 8:20 am

Re: Category Alternate Layout does not use defined layout

Post by stefwilliams » Fri Jan 13, 2012 6:46 pm

Thanks!
Having had a bit of time to think about this since posting, I was going to try exactly this. Good to know I won't just be experimenting and can do it right first time :) will try it out on Monday

stefwilliams
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Jul 29, 2009 8:20 am

Re: Category Alternate Layout does not use defined layout

Post by stefwilliams » Mon Jan 16, 2012 11:17 am

Some progress, but not quite there yet.

I've copied :
/components/com_contact/views/categories/tmpl/
default.xml
default.php
default_items.php

to

/templates/my_template/html/com_contact/categories/
grid.xml
grid.php
grid_items.php

Then in grid.xml, I changed the title to "Grid menu selection". When I load up the menu selection in the backend, "Grid menu selection" is there, but when I choose it, the default.php file is still being loaded.

Is there something else to change in the xml file to direct it to grid.php?

I also don't understand what the original values in default.xml mean, for example: title="COM_CONTACT_CATEGORIES_VIEW_DEFAULT_TITLE"
option="COM_CONTACT_CATEGORIES_VIEW_DEFAULT_OPTION"

Where does that title and option value come from?

[EDIT]
Just found out that "COM_CONTACT_CATEGORIES_VIEW_DEFAULT_TITLE" refers to a line in
en-GB.com_contact.sys.ini
Does that mean I need to add an option pointing to my 'grid' layout? Either in the lang file, or directly in the xml? If so, how do I do this? I've tried putting option="grid.php" and it doesn't work.
[/EDIT]

[EDIT #2]
Ok, so now, I've got copies of the default.xxx files in my html over-rides folder as well, and choosing my menu selection will now load these default.php files, rather than the ones in the core component. This is better than not loading anything from my /html folder, but still not right. Something is obviously still making it look for 'default' but I can't find any other reference, or any way to force it to look at my 'grid' files.

Is there some way to tell my grid.xml that it's supposed to be using the grid_xxx.php files?

Also, and I don't know if this is relevant, I tried changing the lang file mentioned above, and have put in references to _GRID_ in place of _DEFAULT_.

This loads everything fine, but in the Menu Manager, once I've selected my menu, the Menu Item Type still displays as 'List All Contact Categories' , ie, the default, instead of displaying my grid description. It all makes me think that something, somewhere is still explicitly inserting a 'default' value.
[/EDIT #2]

stefwilliams
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Wed Jul 29, 2009 8:20 am

Re: Category Alternate Layout does not use defined layout

Post by stefwilliams » Tue Jan 17, 2012 9:40 am

OH!!

Just re-read this page: http://irislines.com/blog/category-cate ... hoose.html which is linked somewhere above... and it says that what I'm trying to do works for everything except com_contact/categories and this is what I'm trying to do it for!

That explains a lot... I'll try doing it for /category instead.

dansky
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Thu Jan 10, 2008 4:42 pm
Location: Italy
Contact:

Re: Category Alternate Layout does not use defined layout

Post by dansky » Thu Feb 02, 2012 4:40 pm

So, this is the answer ?!
As with component layouts, category layouts only will show if (1) they are
specified for the category in the global or category parameters and (2) there
is no menu item specifically for this category (for example, List Contacts in a
Category, List Newsfeeds in a Category, List Weblinks in a Category, Category
List, Category Blog).
It's impossible to believe that I cant point a root category with a menu item and not having the layout I assigned to the same category. The only workaround as many of you did, is creating a double set of overrides one for the category and the other for the menu item (with the xml). Let me say that this looks like an awful way... we're gonna fill our folder with duplicates...

Please, let's find a better way for this... Hope for future joomla updates for this issue...

Archy108
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Mon Mar 05, 2012 7:21 pm

Re: Category Alternate Layout does not use defined layout

Post by Archy108 » Sun May 20, 2012 7:50 am

Well, I have read all posts and I still don't understand how to make it work.

I just want to say that test.php is working but it isn't loading test_item.php.

Did anyone find the solution?

alekks
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Wed Jan 23, 2008 8:05 pm

Re: Category Alternate Layout does not use defined layout

Post by alekks » Mon May 21, 2012 7:30 pm

I am also struggling with this. I'm on the verge to just skip joomla all together.

I want two different layouts for two different menu items using the Category Blog layout viewing two different categories.
So, I've two different layouts, and from what I understand I have to use the AMI (alternative menu item) approach so the files I've got in my html folder are:
cat1_item.php
cat1.php
cat1.xml
cat2_item.php
cat2.php
cat2.xml

I've made the changes to my menu items so they now are using the AMI:s created by the xml files. The category that I'm required to choose is set to cat1 respectively cat2. The categories are, in the category manager set to "Use Global" (have also tried to use From component: "Blog") in the Alternative layout drop down menu.

The problem for me is now that while something is happening on the page, not the right thing is happening. Only the titles or headlines for the articles are shown in a Category list table when I look at the html that is being output. I have no idea where this come from.

Can somebody go through this with me kindergarden steps?

What am I doing wrong and what should I do to make this work?

Thanks a lot!

lgt363
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Mon Oct 08, 2012 3:51 pm

Re: Category Alternate Layout does not use defined layout

Post by lgt363 » Sat Dec 08, 2012 1:10 am

any ideas on an attractive alternate layout for category pages in J2.5? ... I'm looking for something attractive, with images ...

spinanicky
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sun Apr 07, 2013 4:16 pm

Re: Category Alternate Layout does not use defined layout

Post by spinanicky » Sat Apr 20, 2013 12:10 am

I have created a visual tutorial for this: http://www.inkhorn.ca/joomla-custom-art ... menu-link/

Hope it helps!!

2fik
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 205
Joined: Tue Feb 02, 2010 9:52 pm

Re: Category Alternate Layout does not use defined layout

Post by 2fik » Mon Jun 03, 2013 11:24 am

hello,
I solved the Featured Alternate Layout with :
  • create two files myfeatured.php and myfeatured.xml with change of xml file like in this link http://docs.joomla.org/Layout_Overrides ... Menu_Items
    copy a /components/com_content/articles/views/tmpl/featured/default.php to
    /templates/your-template/html/com_content/featured/default.php
    add this code

    Code: Select all

    // Check for layout override
    $active = $app->getMenu()->getActive();
    if (isset($active->query['layout'])) {
      $this->setLayout($active->query['layout']);
      $this->display(); //display(null)
      return;
    }
    after line 13 or 14 to the file /templates/your-template/html/com_content/featured/default.php
and you can write you code in myfeatured.php


and thank you benno for your solution

TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

Re: Category Alternate Layout does not use defined layout

Post by TheCellarRoom » Thu Jun 20, 2013 2:38 pm

I realise this thread is for category layouts, but i'm having the same issue with Joomla 3.1 and normal article layouts.

I cannnot get my code in templatename/html/com_content/article/myversion.php
to override the default.php version.

No menu items exist and these articles can be found from with in a category list page, this will always be the case.

is there a solution for this?

Neillithan
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Fri Mar 07, 2008 3:59 am

Re: Category Alternate Layout does not use defined layout

Post by Neillithan » Sun Aug 04, 2013 1:05 am

spinanicky wrote:I have created a visual tutorial for this: http://www.inkhorn.ca/joomla-custom-art ... menu-link/

Hope it helps!!
Thank you for this visual tutorial. I was trying to override an article and I couldn't get the article to override because it was linked from a menu item as a "Single Article". Following your tutorial solved the problem I was having.

Suggestion: When you get to the step regarding modifying the XML file, it should be recommended to keep the "title" similar to the "menu item type".

For example: If I'm modifying a "Single Article", the title in my xml file should be "Single Article (Custom)" or "Single Article (Neil's Override)". Etc etc.

This will keep things tidy in the backend.

Thanks for the tutorial! :-)
-Neil

User avatar
malkowitch
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Fri Jun 12, 2009 10:23 pm
Location: Poland
Contact:

Re: Category Alternate Layout does not use defined layout

Post by malkowitch » Wed Aug 21, 2013 1:22 pm

There is simple solution for this (it happen to me with 3.1).
The easiest way is to copy your custom layout files also to view templates directory in component. For example in my case:

Code: Select all

/templates/red/html/com_content/categories/custom.xml
/templates/red/html/com_content/categories/custom.php
/templates/red/html/com_content/categories/custom_items.php
into:

Code: Select all

/components/com_content/views/categories/tmpl
Now when you will add menu link to your layout template will be build using your custom files from html so you don't have to touch copied files again. Just edit template files.

Why it is better?
1. Update doesn't touch your files so template will work after upgrade
2. You don't have to edit system or component files
3. Copy past is always easier :)

User avatar
lausianne
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 154
Joined: Thu Apr 06, 2006 3:15 pm

Re: Category Alternate Layout does not use defined layout

Post by lausianne » Wed Sep 10, 2014 3:23 pm

Years later ... apparently there's still no good solution.
My quick & dirty workaround:
Load alternative layouts conditionally in blog.php depending on the page title. Of course it will break when the page title is changed.

Code: Select all

<?php
$this->item = & $item;
if ($this->params->get('page_title') == 'Portfolio') {
	echo $this->loadTemplate('portfolio');
} else {
	echo $this->loadTemplate('item');
};
?>

jessica albert
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Sep 08, 2014 10:01 pm

Re: Category Alternate Layout does not use defined layout

Post by jessica albert » Wed Sep 10, 2014 3:33 pm

HI,
I´m facing the same problem and I´ll resume what I found out:
- if you have a menu item pointing to the category Joomla! will use the layout specified on the menu link and that´s the reason the alternative layout doesn´t work.


Locked

Return to “Joomla! 2.5 Bug Reporting”