Home Conticreative Blogs The Joomla Blog Assigning Joomla templates - URL syntax and sh404sef compatibility

Blogs - The Conticreative Joomla Blog

Assigning Joomla templates - URL syntax and sh404sef compatibility

Attention: open in a new window. PDFPrintE-mail

Written by Marco Conti Saturday, 26 June 2010 12:31

Share |
User Rating: / 0
PoorBest 

Joomla has the ability to assign any template to any given page (as long as that page is linked from a menu) which is a very useful feature. However, often this trick does not work very well with sh404SEF turned on. At least not with the version currently in stable release (A new Beta version is coming out and I'll bring you a full review - hopefully in print and video - as soon as I have a chance to test it).

The other day I had a need to create an alternate template I could assign to a single page in the site. I needed a full set of modules to appear on the left column where normally the navigation and several other modules reside. Doing this is possible with a number of extensions, mostly modules like NoNumber.nl Advanced Module Manager, Metamod and others. However, in some cases swapping the template itself can be a more manageable solution (interestingly, the developer of Metamod has an extension called "MetaTemplate" that may have helped as well). In any case, for various reasons it was the solution I needed.

template

The coding was easy. I simply cloned the template, renamed its folder and renamed its name in the XML file. Then I found the left column code in the index.php file (some templates these days use frameworks and keep that code in a sub-directory, so watch for it) and I changed the position name "left" to "left_alt" in the jdoc:include that generates the position in Joomla templates.

Original Code:

<jdoc:include type="modules" name="left" style="xhtml" />

New Code

<jdoc:include type="modules" name="left_alt" style="xhtml" />

I also kept most of the links referring to the CSS and JS files of the master template unchanged (i.e. pointing to templates/master_template/css/filename.css), giving me the ability to edit the master template's css files and have those changes reflect in the alternate template. Otherwise, each future template edit would have had to be duplicated in the alternate template for consistency. That's a pretty neat trick if you ask me.

So far so good. (by the way, if the above is Greek (or geek) to you, I will probably make a "10 Minute Joomla! Tips" screencast about this topic soon, so bear with me).

Buy Jomsocial

Everything went fine in the staging site, but when I moved the change to the live site something disturbing happened. The template refused to load. Likie all good staging sites, SEF URLs are kept off.

The first thing that came to mind as the culprit was sh404sef and I was right. Problem was that no matter what I did: refresh the cache, purge URLs, dance around the room wearing nothing but my underwear and singing opera, made a difference. The template was not going to load.

Without SEF URLs this would have been a 2 minute job. With SEF URLs turned out to be an ordeal.

However, I remembered that in the really old days the Joomla demo sported a module that allowed a front end user to change the template on the fly with any template loaded in the template manager. That module is long gone from the core but I remembered that it added a parameter to the URL to accomplish that feat. I just didn't remember the syntax. I tried temp=name, tp=name, tp&name and so on. I just missed the right syntax by a hair. A quick Google search returned the right parameter:

index.php?Template=template_name

Sure enough it worked like a charm in the staging site. The URL looked something like this:

index.php?option=com_content&id=243&view=article&template=template_alt
(for you eagle eyed, I edited the URL to shorten it a bit)

Note the & (ampersand) needed to insert the snippet in the Joomla URL. Also, the template syntax can be inserted pretty much anywhere in the URL as long as it's after "index.php?" and an & is used.

Start Learning Joomla

However, in the live site once again sh404sef would not hear it of loading the requested template.
Ultimately, I tried so many ways to make it load that I am not 100% sure which one really worked, but by the time I'll shoot my podcast on the topic I am hoping to be more positive about the right technique (or, hopefully, the new sh404sef beta will solve this issue). But for now what I think finally worked for me was to:

  • Clear all the cache everywhere (not sure if necessary, but a good idea).
  • Go to sh404sef and delete the sef URL it created for the page in question
    (go to components > Sh404 > View/edit SEF URLs search for the "safe" url in the log, click the checkbox and hit 'delete' )
  • Assemble the URL by hand in notepad to look like something like this:
index.php?option=com_content&id=123&view=article&template=template_alt
  • and paste it in the browser's address field, hit <return> and hope.

To my relief, the alternate template loaded and the "Human Readable" url looked something like this:

http://domain.com/article-title?template=template_alt

I tried getting rid of the last part of the URL but at some point I decided that it was too much effort for the result I was going to get. There may be still a solution for that, but not today.

iContact.com - Email Marketing Service

I also tested the link to make sure it would not break again. I purged the SEF URLs, I refreshed the cache and pretty much used every trick I know to break it. As of today it's still holding strong. The only thing I have not tried was turning sh404 off and then on again. But I'll try that in the near future on a staging site.

I hope this little tutorial and recount of my "struggle" will help someone in the same bind. Changing templates on certain pages is a powerful feature of Joomla. If used smartly it can make challenging site design much easier to implement. But paired with most SEF URL schemes it can create problems. Hopefully the above post will help you solve them and come up with your own elegant solutions.
Post them here if you do. Peace.

*cc*

 

NoNumber! Free and Powerful Joomla Extensions

 

Trackback(0)

TrackBack URI for this entry

Comments (6)

Subscribe to this comment's feed

Show/hide comments
thanks alot
I am using this in my website
ahmad balavipour , September 11, 2011
The actual reason for this
Hi
This is shumisha, author of sh404sef. I don't have all details of your actual site, but such situations is very common and:
1 - is not a bug
2 - is a consequence of a feature
The feature is the duplicate content protection sh404sef provides. Duplicate content happens a lot in Joomla, especially due to the way it tends to attach a page to a menu item.
With sh404sef, a page (article) url is not linked to the menu item (as identified by its Itemid) but instead only to the article/product title and/or category.
In the same way, Joomla! attaches a template to a menu item, also identified by an Itemid.
When you loose the expected templates (or modules, the same behavior happens with module), it most likely means the same page can be accessed through several Itemids, and sh404sef is not using the Itemid you want.
You can check that by looking up the Duplicate fields in the Url manager. If you got any duplicate, then click on the Duplicate counter, and you'll see a list of duplicate urls. Select the one with the correct Itemid, and click on the "Main" button, to make it the preferred url.
Joomla! Itemid has long been a confusing concept, but it is also quite powerful. If you're faced with module and/or templates that do not behave as expected, you should go to the URL manager and check out duplicates.

Rgds
Yannick Gaultier , March 28, 2011
Joomla
The coding and way mentioned in the post to have a new template to any of the page is working and i have added template to one of my page with the use of the way mentioned i the post. Nice application of Joomla.

Joomla , March 03, 2011
Joomla
Was searching for the way with the help of which i can assign template to a page with the help of Joomla. Really very informative post and helped me out for what i was searching for.
Spammer , March 03, 2011
Yep! Ended up here looking for this solution.
Are we the only ones experiencing this issue>and is it still not fixed in sef404! Bummer, I'm going to try the switch, i suspect sef as well, and I knew about the switch but just didn't know how to implement it. Thanks for the detail. I'm going now to test it.
Suzanne , January 17, 2011
www.bellenew.com
I learned more on you post, thank you .
green scarf , September 13, 2010

Write comment

smaller | bigger

busy

10 Minute Joomla! Tips Blog

Conticreative joomla book reviews

Independent joomla hosting reviews

Joomla Training

Conticreative offers Individual and Corporate training (in person or online) on Joomla, Wordpress, Zen Cart and other leading Open Source scripts.

[Read More...]

Books

Books we suggest...

 

Spreadfirefox Affiliate Button
switch the positions on