Page 1 of 1

Adding new layout to existing component

Posted: Wed Mar 19, 2008 9:35 am
by koyan
Hallo all,

Starting from the request that is described in Standard Section Layout and category list - Links and in section list > category blog, I have created a new layout, for the com_content\views\section\tmpl

The new view shows the categories of a section, as a blog, and not as a list.

In order to do that I modified the default.php and default.xml (the second one in order to add the new parameters).

It all works well when I have them named default.php and default.xml.

The question is: is there any way that I can have my new layout as an option in the "Select Menu Item Type" in administration?

I want to add it as a new option, so that it does not override the default one, so that I can share it with others.
My first thought was to rename the default.php and default.xml to files with new names (aka blog_category.php and blog_category.xml) and change the descriptions in the xml file. I did that, but now how do I tell joomla to give this view as well as an option?

Re: Adding new layout to existing component

Posted: Wed Jun 18, 2008 2:24 am
by deejson
I would love to know the answer to this as well....anyone?

Re: Adding new layout to existing component

Posted: Fri Oct 10, 2008 2:50 pm
by nniico
This post is a bit old, but an answer would have saved me some reverse engineering time.
To add a new layout for a specific vew (such as article, archive, category, section or frontpage), create a new template in

Code: Select all

/components/com_content/views/<view>/tmpl/
For example, if you define an accordion template for the categories, it should be named like this :
/components/com_content/views/categories/tmpl/accordion.php

And that's all. Of course, if you need to define specific parameters, you need to create an "accordion.xml" file in the same folder. Take a look at the existing layout for a start.

I'm not fond of adding files to the tree of an official component, as it will make updates more complicated, so if somebody has a better solution, I'd be glad to know it.

Re: Adding new layout to existing component

Posted: Fri Mar 20, 2009 1:04 pm
by mwithi
Hi Koyan, I'm very new in Joomla and I was looking for the same same solution!

Have you already shared your layout somewhere?

Re: Adding new layout to existing component

Posted: Wed Mar 31, 2010 2:54 pm
by ludder
I'm still curious to know if this is possible without hacking the core element.

Re: Adding new layout to existing component

Posted: Tue Apr 06, 2010 4:22 pm
by erichf
You can override an existing layout using the method that is described at: http://developer.joomla.org/tutorials/1 ... oomla.html . This method confines your changes to your template's directory so you don't have to make any changes to the core file system.

However, if you need to have multiple layouts, then the method in the tutorial doesn't apply because it overrides the existing layout but doesn't create a whole new layout.

Re: Adding new layout to existing component

Posted: Wed Jul 28, 2010 11:10 am
by davide.taddei
Hello, I think it's good solution to simply ad a new layout file to the tmpl folder of the view because it's in any case upgrade-safe.

By the way I'm triying to challenge a new problem: i would like to add a new view to the contacts component.

I would like to ad a page with a list of the categories of the contacts, so what I'm triying to do:

1) add a new folder name "CATEGORIES" to the component/com_contact/views/ directory;
2) create a new view.html.php file;
3) create a tmpl folder;
4) add a default.php file;

In the backend I can associate a new link in the menu with the "CATEGORIES" view, but when I load the page it returns an error, do you have any idea wich is the problem?

Re: Adding new layout to existing component

Posted: Wed Jul 28, 2010 11:20 am
by davide.taddei
Well.. I solved the problem by myself :-)

The controller of in the com_contact component loads a model with the same name of the view, so it need to add a categories.php file in the folder component/com_contact/moddels/ directory;

hope it will be useful for someone ;-)

Re: Adding new layout to existing component

Posted: Wed Oct 13, 2010 6:28 am
by piotr_cz
Hey.
In case it would help somebody: some of the model logic is restricted to specified layouts.
For example: pagination in the category view is hardcoded in the model to work only with blog layout so if you want to create new layout with pagination, you have to include the logic in the view itself.
Or create own component.

Re: Adding new layout to existing component

Posted: Fri Apr 01, 2011 2:16 pm
by chongkan
nniico's answer worked at the first time for me on 1.5.x and, if you follow nniico's method, instead of:
davide.taddei wrote:
1) add a new folder name "CATEGORIES" to the component/com_contact/views/ directory;
2) create a new view.html.php file;
3) create a tmpl folder;
4) add a default.php file;
+
davide.taddei wrote:Well.. I solved the problem by myself :-)

The controller of in the com_contact component loads a model with the same name of the view, so it need to add a categories.php file in the folder component/com_contact/moddels/ directory;

hope it will be useful for someone ;-)
Then you can use the existing view and model and just add a different one if you really need to.