Connect with us!Join the Official Joomla! Book on Facebook Subscribe to the Official Joomla! Book News Feed Join the Official Joomla! Book on Twitter Join us on the Joomla! Forum Join us on Joomla! People
 

Translate

Login/Register

Support Joomla! Buy a Book!

Click on the book to purchase now!

Every purchase of The Official Joomla! Book directly funds the Joomla! project.

Read the press release regarding Joomla! Press at joomla.org

Read the Joomla! Press mission statement and find all Joomla! Press books at joomla.org

tryjoomla

Alternative Layouts in 1.6

Attention: open in a new window. PDFPrint

Labels: 1.6

1.6 is so amazing, really. I've said all along that it will be a webmaster's release and I really think it is.  Mostly people have paid attention to ACL but there are lots of other great details. One of the coolest features is the new alternative layout option.

We all know that in 1.5 you could do a layout override. Which is awesome, but also frustrating because of how it is "all or nothing." That is if you use a template with an override you always have to use the override. If you wanted the core layout for something you needed to go through a song and dance.  No more!

In 1.6 items and categories (should) have a parameters that lets you select any alternative layout from either the core or the default template. So in my example, I'm going to use an alternative layout for the weblinks category view.

Just as in 1.5 I put my layout files in the /html/com_weblinks/category folder. But instead of caling it default.php, I'm calling it newlinks.php (sub layout template naming works the same as always). Only now. ... I get the option to pick what layout I want.

selectlayout

I made a simple override where I just moved the name of the category to the bottom of the page. An voila! here is how it looks:

althernativelayout

If you want to try this at home, right at this moment you need to apply two simple (easy to apply by hand) patches that are in the Tracker:

Those patches will make the weblinks category work. I'm going to spend some time today making sure that the same issues aren't elsewhere.

A few things to note. First these apply to items not menu items. So you can't at this point have multiple layouts for the same exact item if for some reason that is something you want.  Secondly, as of now there is no way to set this globally. So if you always want to use an alternative layout you'll have to select it each time--but if you really mean that, you should probably do default anyway.

Alternative layouts use the componentlayout field in JForm and it's just one indication of the tremendous impact that JForm is going to have for Joomla! users.

8 Comments

  1. Obviously whoever decided to write that patch has not a single developer bone in him/her. Any developer, even a semi-knowledgable one, would tell you that this is the road to oblivion. It is common for developers to write different layouts on the same view to accommodate for different tasks in order to avoid views proliferation and scope fragmentation of associated models. For example, we may have a view=checkout with tasks named billinginformation, overview and payment. Each of them, obviously, needs a different layout as it has to accommodate for different data display and input needs. Having one view per task would be a silly mistake, as the model code would be triplicated among those three similar views.
  2. With that patch applied it is extremely easy for someone to create a menu link to the billinginformation task with the overview layout. What a great way to break a site! Then, whose fault will it be? The component developer's for not making enough checks against stupid design decisions in the framework? The user who is oblivious to what he has done? Or, maybe, Joomla!'s for having a framework which doesn't make any sense at all? I suggest that if you want to duplicate K2's features you take a look at K2's code and figure out how these guys are doing that without violating the framework with such design atrocities. Or, maybe, hire a real developer who understands framework design to write code.
  3. Nic, You are confusing views and layout overrides. Layouts are not views, they render views. If you want to have additional views then you would add whole new view with its own layouts, xml and model and you could override whatever layouts you have either with the same name (as in 1.5) or optionally with different names (as in 1.6). Neither of these patches touches the framework. Anyway I welcome you following the test instructions on the tracker reporting your results, and maybe proposing another way to make that parameter (which is in the code base but not working) work as described in the API in a new patch. Thanks for your interest!
  4. No, Elin, I know exactly what I'm talking about. You are the one who doesn't understand the structure of a component. You confuse what you can assign to a menu with what the developer writes. In all fairness, if we wanted our users to use any random layout file with any task on a given view, why are those XML files in there? Ask yourself the simple questions and you shall find the reason behind the framework's design choices. IMHO, each component should allow for multiple template overrides, but such a change would be backwards-incompatible and not apt for a minor release of the software. Your patch does override the default behaviour of the framework (in retrospect, "modify" was a very bad choice of words, you are right) in ways never really intended. The thing is, if we give the user that option on com_weblinks we'll soon be tempted to do that on com_content or another complex component and then you'll see why this is a bad idea ;)
  5. My response got a little long so I posted it in a new article. http://officialjoomlabook.com/elin-waring-official-joomla-book-blog/more-on-alternative-layouts
  6. Interestingly, it HAS been in com_content since alpha.
  7. Where did you say you are putting that?? I have searched but I only find people telling how to do overrides, not alternates. I need some help in adjusting modules for the admin side. thanks in advance.
  8. It goes in the same place as an overide, in the html folder of your template. In Beez 5 you will see an example for the single contact view. It is in html/com_contact/contact/

Add Comment

 
VALID CSS   |   VALID XHTML