I am using Drupal 4.7 with CCK and pathauto (and thus clean URLs). I am using a heavily customized theme based originally on the Spread Firefox theme.
Right now I am using customized template.php and page.tpl.php files to display particular templates (page-[content-type].tpl.php) depending on the content type. Since I'm using pathauto, these don't appear as "node/nid" (although you can still go to those addresses) but as the arbitrary name of the page (e.g. http://example.com/whatever).
What I want to be able to do is to tack on something in the URL to serve users the SAME template with a DIFFERENT stylesheet. Moreover, I want to be able to have MORE THAN ONE of these.
So if someone were to go to http://example.com/whatever?print=y or http://example.com/whatever/print or something of that sort, one would get print.css rather than the default theme and Drupal stylesheets. And if one were to go to http://example.com/whatever?silliness=y or http://example.com/whatever/silliness, one would get silliness.css.
This is basically a "stylesheet switcher," except that I want to be able to control it through the URL, and I don't want it to set a cookie (as most switchers do) because I only need the alternate stylesheet for that one page.
1. I started by looking at the print module but this does both more than and less than I want.
- It does a bunch of printer-friendly formatting and moving around (such as with the links), which is great, but more than I need.
- It forces you to use a print.tpl.php template -- I want to use the SAME template for EACH given content type, each of which has a different template. This would mean I'd have to have one single print template for all content types, which isn't going to work.
- It only gives you the option of one alternate stylesheet (print.css).
2. Then I tried using $_GET with the method outlined by eliza411 in this post. This worked great, and I would still be using it if I could be. Except that once I upgraded CCK to the current version (I had a pre-fieldgroup version) none of those links worked anymore. I can't explain why upgrading CCK broke these, but nothing else about my site has changed. Now if you go to whatever?printme=y it ignores what it should be seeing within those PHP if tags -- so the alternate stylesheet never gets loaded, and everything looks exactly the same.
If anyone knows what might of happened there, I'm all ears -- because that was really the perfect solution.
3. I checked out the very promising-sounding handbook page on "customising the full page layout and sections based on path." This seemed to fail for a number of reasons:
- The arg()s don't seem to really work with clean URLs in place -- although I confess I don't understand the concepts of the arg()s too well
- The things I want to add to the URL are arbitrary and don't conform to an existing page. So unlike going to /admin/blah or /node/blah or taxonomy/blah, I want to go to (the equivalent of) /node/18/blah, where no page exists. It doesn't look like this method works in this way.
I tried each of the suggestions on that page and in the comments but none of them worked.
Now I'm at a loss. This seems like it should be relatively easy -- switch the stylesheet based on something in the URL -- but maybe I'm deluding myself. I liked the $_GET method because I could actually switch out many different parts of my templates based on that value, so I could easily turn off the default style-loading of Drupal and load only the print stylesheet, and also insert a link (as eliza411 does) back to the default page. Alas, that method no longer works for me.
Any ideas?
Comments
One alternate idea
I'd also be OK with something in the URL causing Drupal to load a different template -- and that template would simply have the alternate stylesheet specified. It doesn't seem as elegant, because then I have to maintain two templates, but it would allow for basically the same thing and still overcome print.module's drawbacks.
Wrong link
This is the correct link for customising the full page layout and sections based on path. Oops.
Figured it out!
In fact it was the CCK upgrade. Apparently the CCK node types that the page template looks for went from being content-[nodetype] to content_[nodetype]. So it was looking for the first of those, not finding it, and loading the default template -- which means it was never seeing the template with the $_GET tests on it. Now it is, and those are working, and it's beautiful. So in case anyone else runs across this thread...that's how to do it.