Page 2 of 2

Re: Category Alternate Layout does not use defined layout

Posted: Tue Dec 20, 2011 9:49 am
by hoochicken
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; 

Re: Category Alternate Layout does not use defined layout

Posted: Fri Jan 13, 2012 3:46 pm
by stefwilliams
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:

Re: Category Alternate Layout does not use defined layout

Posted: Fri Jan 13, 2012 5:32 pm
by barback
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!

Re: Category Alternate Layout does not use defined layout

Posted: Fri Jan 13, 2012 6:46 pm
by stefwilliams
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

Re: Category Alternate Layout does not use defined layout

Posted: Mon Jan 16, 2012 11:17 am
by stefwilliams
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]

Re: Category Alternate Layout does not use defined layout

Posted: Tue Jan 17, 2012 9:40 am
by stefwilliams
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.

Re: Category Alternate Layout does not use defined layout

Posted: Thu Feb 02, 2012 4:40 pm
by dansky
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...

Re: Category Alternate Layout does not use defined layout

Posted: Sun May 20, 2012 7:50 am
by Archy108
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?

Re: Category Alternate Layout does not use defined layout

Posted: Mon May 21, 2012 7:30 pm
by alekks
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!

Re: Category Alternate Layout does not use defined layout

Posted: Sat Dec 08, 2012 1:10 am
by lgt363
any ideas on an attractive alternate layout for category pages in J2.5? ... I'm looking for something attractive, with images ...

Re: Category Alternate Layout does not use defined layout

Posted: Sat Apr 20, 2013 12:10 am
by spinanicky
I have created a visual tutorial for this: http://www.inkhorn.ca/joomla-custom-art ... menu-link/

Hope it helps!!

Re: Category Alternate Layout does not use defined layout

Posted: Mon Jun 03, 2013 11:24 am
by 2fik
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

Re: Category Alternate Layout does not use defined layout

Posted: Thu Jun 20, 2013 2:38 pm
by TheCellarRoom
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?

Re: Category Alternate Layout does not use defined layout

Posted: Sun Aug 04, 2013 1:05 am
by Neillithan
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

Re: Category Alternate Layout does not use defined layout

Posted: Wed Aug 21, 2013 1:22 pm
by malkowitch
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 :)

Re: Category Alternate Layout does not use defined layout

Posted: Wed Sep 10, 2014 3:23 pm
by lausianne
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');
};
?>

Re: Category Alternate Layout does not use defined layout

Posted: Wed Sep 10, 2014 3:33 pm
by jessica albert
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.