Adding new layout to existing component

Your code modifications and patches you want to share with others.
User avatar
koyan
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 185
Joined: Tue Aug 23, 2005 7:17 pm
Contact:

Adding new layout to existing component

Postby koyan » Wed Mar 19, 2008 9:35 am

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?
You do not have the required permissions to view the files attached to this post.
http://www.sintagespareas.gr :  Recipes in Greek

User avatar
deejson
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Wed Sep 05, 2007 9:42 pm
Location: Seattle, WA

Re: Adding new layout to existing component

Postby deejson » Wed Jun 18, 2008 2:24 am

I would love to know the answer to this as well....anyone?

nniico
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Oct 10, 2008 1:50 pm

Re: Adding new layout to existing component

Postby nniico » Fri Oct 10, 2008 2:50 pm

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.

mwithi
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Mar 20, 2009 12:55 pm

Re: Adding new layout to existing component

Postby mwithi » Fri Mar 20, 2009 1:04 pm

Hi Koyan, I'm very new in Joomla and I was looking for the same same solution!

Have you already shared your layout somewhere?
"help will save the world!"

User avatar
ludder
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Feb 03, 2010 9:06 am

Re: Adding new layout to existing component

Postby ludder » Wed Mar 31, 2010 2:54 pm

I'm still curious to know if this is possible without hacking the core element.

erichf
Joomla! Explorer
Joomla! Explorer
Posts: 314
Joined: Fri Feb 26, 2010 4:01 pm

Re: Adding new layout to existing component

Postby erichf » Tue Apr 06, 2010 4:22 pm

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.

User avatar
davide.taddei
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Tue Jan 22, 2008 8:01 pm
Contact:

Re: Adding new layout to existing component

Postby davide.taddei » Wed Jul 28, 2010 11:10 am

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?

User avatar
davide.taddei
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Tue Jan 22, 2008 8:01 pm
Contact:

Re: Adding new layout to existing component

Postby davide.taddei » Wed Jul 28, 2010 11:20 am

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 ;-)

User avatar
piotr_cz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 164
Joined: Mon Mar 30, 2009 11:27 am
Location: www
Contact:

Re: Adding new layout to existing component

Postby piotr_cz » Wed Oct 13, 2010 6:28 am

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.
work hard, party harder
http://smartwebstudio.com

User avatar
chongkan
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Aug 26, 2008 4:33 am
Contact:

Re: Adding new layout to existing component

Postby chongkan » Fri Apr 01, 2011 2:16 pm

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.
Saludos,
--
Chongkan - Likan Development - Diseño Web y Desarrollo a la medida - http://www.likandevelopment.com


Return to “Core Hacks and Patches”

Who is online

Users browsing this forum: No registered users and 1 guest