Hi! I'm trying to find a user-friendly way to be able to specify a different theme for specific pages through the admin interface, so a non-techie site admin doesn't have to do any template coding.
The best idea that I've been able to try is to use the template-switching snippets in Customising the page layout based on path, and setting a unique path alias for those pages. In my case, I set the page alias to "store/product1" and the template to switch on arg(0)=="store". Unfortunately arg(0) doesn't seem to apply to path aliases, so it doesn't work.
Do you have any other ideas that I could try? I've thought of switching templates based on taxonomy, node number, etc. but it has to be something that can be activated without editing the template, and so far all of the methods I've tried require new nodes/terms to be added to the logic in the template.
Thanks in advance!
Comments
Hmm, good question
If you don't get the information here, maybe you should comment here: http://lullabot.com/articles/hacking_phptemplate ?
Thanks! Done.
Thanks! Done. I'll post back here if I get a solution.
I asked the same question
I asked the same question and got some good feedback. Check out: http://drupal.org/node/55075
Thanks, TheEdge. I had seen
Thanks, TheEdge. I had seen most of those resources already, but so far I still haven't been able to do what I want. I may be missing something obvious, but I don't see a way in any of those methods to set a "switch" within the admin interface to make a page use a different template. It's easy to do if you can edit the template directly, but I want to set it up for a non-techie site admin so they don't have to touch the template.
I haven't fully investigated setting up a new node type to use a different theme, so that will likely be where I focus my next experiments. I'll keep you posted!
An option for you might be
An option for you might be to use a different variation on the lullabot article: it's something I use to apply different styles to different sections. It uses clean urls and pathauto for selecting a template to use.
This will select a page template to use based on the actual address of the page, hence the dependency on clean urls. pathauto is not a requirement, but it does make it easy to automatically categorize your new content into one of the sections.
If none of the rules match, a default template is passed through for the site to use.
Once this is done (put in page.tpl.php, remove everything else and paste that in page-section1.tpl.php and page-section2.tpl.php) you can use the section templates with custom CSS, body tagging and a host of other tricks.
One important thing to note about this system though:
change the [2] into the actual component of the url you want to use, with the / acting as a delimiter. (http:// is not counted)
so for
http://my.site.tld/drupal
would require
if ($section[1] == "section2"
and
http://my.site.tld/drupal/my_section
would require
if ($section[2] == "section2"
and so on.
---
GU d- -p+ c++++ l++ e* m* s+ n+ h+ f? g+ w+++ t- r y?
Junior developer @ Madcap B.V.
http://www.madcap.nl
It may be easier to use a
It may be easier to use a switch statement, for example:
That's true, it is more
That's true, it is more elegant that way. The main thing is that it works.... having elegant code is just gravy.
Thanks for your help!
Error
I get an error trying out either of these pieces of code. With yours Ryanbach i get this:
Parse error: parse error, unexpected ':' in /home/mydomain/public_html/themes/friendselectric/page.tpl.php on line 5My page.tpl.php file just has this code inside...everything else removed.
There is an extra colon in
There is an extra colon in the layout1 line. Should be:
case 'section1':YES!!!!
Thanks, BlackSash! That was what I needed. I didn't get the distinction between using arg() and explode() depending on whether the site uses clean urls -- which mine does.
I think I'll post this into the handbook pages so others don't have the same trouble.
Thanks again!
Is this correct
If i have a section of my site that uses path aliases of:
mysectiona/*
mysectiona.html
Would it be:
Thanks
Almost.
Almost. If you use a path alias:
mysectiona/mypage.html
it would be:
This page should help clarify as well: http://drupal.org/node/46027
Thanks :)
Even if it is like this:
mydomain/mysectiona/*
mydomain/mysectiona.html
Wouldn't they both be [1]?
Not quite. The line that
Not quite. The line that says:
$section = explode("/", $uri_request_id);splits your URL into an array, based on its segments that are separated by a slash. So if your path is mydomain.com/mysectiona/mypage.html, then you would get:
$section[0]=="mydomain.com"
$section[1]=="mysectiona"
$section[2]=="mypage.html".
In your two examples, you would get:
mydomain/mysectiona/* --> $section[1]=="mysectiona"
mydomain/mysectiona.html --> $section[1]=="mysectiona.html".
Make sense?
---
Arvana
arvanadesign.com
Yes
Clear now, thanks again. :)