By strayhand on
For those interested, I've been playing around with multiple templates, and I have a site up and running that uses this simple hack. http://news.plu.edu
I made some changes to the xtemplate theme file to allow for multiple templates. Check out code below.
Put this at the top of the file.
// Get current template
$current_template = variable_get('mxtemplate_template', 'default');
// Get current directory
$current_dir = $_GET["q"];
// Set template directory (look for path match)
$template_directory = mxtemplate_match_paths ($current_dir, $current_template);
Add something like this function to the .theme file
function mxtemplate_match_paths ($curpath, $curtemp){
/*
** Take current path, match against stored paths
** If a match exists, update theme template
** If no match, assign $curtemp as default theme
** Return theme template
*/
// Pages that should use different templates
$page_home = "49"; // Home is nid #49
$page_campus_news = "5"; // Campus News is nid #5
$page_notices = "54"; // Notices is nid #54
$page_events = "130"; // Events is nid #130
$page_plunews = "31"; // PLU News is nid #31
$page_news = "50"; // News is nid #50
$page_archive = "51"; // Archive is nid #51
$page_classifieds = "13"; // Classifieds is nid #13
$page_newsstaff = "320"; // News Staff is nid #320
$page_photoservices = "321"; // Photo Services is nid #321
$page_facultyindex = "318"; // Faculty Experts index is nid #318
$page_facultylist = "319"; // Faculty Experts list is nid #319
$page_speakersindex = "314"; // Speakers Bureau index is nid #314
$page_speakerslist = "317"; // Speakers Bureau index is nid #317
// Adjust the argument incase the page is being viewed through the admin
$check = arg(0, $curpath);
// Set argument
$argument = arg(2, $curpath);
// Assign alternate templates
if($check == "admin"){
$path_template = "admin";
}
elseif($argument == $page_home){
$path_template = "home";
}
elseif($argument == $page_campus_news){
$path_template = "campus-news";
}
elseif($argument == $page_notices){
$path_template = "notices";
}
elseif($argument == $page_events){
$path_template = "events";
}
elseif($argument == $page_plunews){
$path_template = "plu-news";
}
elseif($argument == $page_news){
$path_template = "news";
}
elseif($argument == $page_archive){
$path_template = "archive";
}
elseif($argument == $page_classifieds){
$path_template = "classifieds";
}
elseif($argument == $page_newsstaff){
$path_template = "news-staff";
}
elseif($argument == $page_photoservices){
$path_template = "photo-services";
}
elseif($argument == $page_facultyindex){
$path_template = "faculty-experts";
}
elseif($argument == $page_facultylist){
$path_template = "faculty-experts";
}
elseif($argument == $page_speakersindex){
$path_template = "speakers-bureau";
}
elseif($argument == $page_speakerslist){
$path_template = "speakers-bureau";
}
else{
$path_template = $curtemp;
}
return $path_template;
}
Within the xtemplate_page function add this below "global $mxtemplate;" but before " $mxtemplate->template->assign(array("
// Get current template
$current_template = variable_get('mxtemplate_template', 'default');
// Get current directory
$current_dir = $_GET["q"];
// Set template directory (look for path match)
$template_directory = mxtemplate_match_paths ($current_dir, $current_template);
If you want to play around with this be sure to backup your xtemplate.theme file. This code is just an example. To make it work on your site you'll have to change it a bit.
Comments
The site looks great! Great
The site looks great! Great example of how multiple templates assigned to different nodes can assist in the design of especially an organizational website...to help differentiate and brand different sections/information types.
I tried this out on a 4.4.2 install to give it a whirl. One thing I had to do was delete line 7 in xtemplate.theme which reads:
$template_directory = variable_get('xtemplate_template', 'default');I now am wondering how to do this with 4.5.0. I caught this comment http://drupal.org/node/9652#comment-14997 and the following. Is there a contributed module that assists with this now?
Is the above method you use strayhand possible in some form or modification for 4.5.0 using just the xtemplate.engine file? It looks like the function that checks the current directory is different...not sure what else...and how much or little work it would take...?
brilliant layout
Hi Strayhand.
Top marks on your site. looks fantastic.
I'm a complete noviceplete novice when it comes to Drupal...can you point me to more info. on how to do what you did?
Cheers
J
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
Hey Jasonm3m, I can further
Hey Jasonm3m,
I can further annotate what I did in 4.4.2 install - completely using the method Strayhand outlines.
First, this applies for when using the xtemplate theme.
All changes are made to the xtemplate.theme file. (make a backup copy :-)
Now, insert the first two pieces of code in order strayhand presents them into the .theme file at the top after the php opening tag and ID line.
Then, delete *just* the last line in this bit, thus delete starting at $template_dir...:
(originally this line appears on line 7.)
Now, insert the last part as strayhand notes above.
Finally, the logic here is to check the nid (node id) of the page the viewer is on, if it matches one of the nid's listed in the mxtemplate_match_paths function, then it will look for the alternate template.
So, you need to customize which pages have different templates and make the appropriate changes in this new .theme lines of code. Go to the pages on your site you've created which you would like to have custom themes. Note their nid - the number at the end of the url. Now, in the .theme file, and modify these lines using the nid's you will have custom pages for:
etc. and delete the extra lines. the second part of the variable after $page_ like "home" is relative and must correspond to further down in the code:
$path_template is saying where to look for the alternate template. You must create a subfolder under themes/xtemplate/home
Create a subfolder for each $path_template statement (each custom template you are calling). Within each subfolder, you will need to have xtemplate.xtmpl and the xtemplate.css file. Modify these files to your liking to get the custom template.
Now, how to do this for 4.5.0 with the xtemplate.engine :-) ?
thanks a million...
cheers for that. Appreciate it. Much clearer and easier to understand.
I've just installed drupal 4.50 and will try and implement the steps you outlined in that.
Will post back up here if I have any joy.
Jason
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
I think it needs some kind of
I think it needs some kind of modification as the $template_directory variable is no longer used to establish the directory as it was previously used on line 8 in 4.4.2. I'm guessing the rest of the code will work, but the code that checks the default template and the directory won't work with 4.5? Is this the missing key?
Another guess is that is has something to do w/ coordinating w/ this line in 4.5 xtemplate.engine file:
Please let me know if you figure it out...thanks!
you can completely ignore the template directory
your template are stored in themes/
and you can set different themes using the $GLOBALS['custom_theme'] variable.
you can switch between any template engine themes.
ie: your one template can be phptemplate, and the other xtemplate. etc.
check out webschuur.drupaldevs.org for the theme switcher based on this functionality(part of core)
--
The future is so Bryght, I have to wear shades.
Multiple Template Hack
Wish that I could be of more help to you. But I'm without a server at the moment and I cannot do any kind of development. This was a hack that I came up with by picking apart the .theme file. If you study the new .theme file for 4.5 you can probably find a work around. I'm not sure how to implement the $GLOBAL variable to selected different themes for different pages.
If you like how this hack works, then you might also consider hacking the path alias module to include a template for each path alias. This was initially how I had things configured. I modified the path module so that I could assign a template to a path. Then I checked for the path within the .theme module. Modifying the path module to include a theme will save you the trouble of hard coding the NID numbers in the .theme file.
My advice would be to investigate adrian's comment and see if you can switch templates using the $GLOBAL variable.
I put this in the conf file a
I put this in the conf file and it works...so far...
I imagine this can be compacted somehow, as I'll be needing to list several pages, and things might start to get slow...but the idea works. Thanks y'all for the info about custom_theme and the original work around. Maybe there is a way to do en/about.* or some expression to get all the pages beneath the en/about path to use one template, as that's how i'll need it. If I come up w/ something I'll post it. This is working in it's raw form for now.
Regular Expressions
I think you could use regular expression in your if statement to look for the pattern "en/about" then you could assign a template if the $current_dir matched the pattern. There are some pretty useful suggestions/examples of regular expression in the forums dealing with "blocks". Also php.net has some examples of regular expression.
Thanks for the code
sections.module
I just released a module called "sections", that allows themes per sections. The here mentioned feature can be implemented in an easy way in this module.
And if this solved you problem, would you be so kind to report back that it helped? This will help others whom are looking for the same solution.
[Ber | Drupal Services webschuur.com]
ben, i downloaded your sectio
ben, i downloaded your sections module but there seems to be files missing, ie there was no sql file in the directory??
www.justride.co.uk
The SQL file has just been added there
http://cvs.drupal.org/viewcvs/contributions/modules/sections/
Please tell me if you succes to make it work.
It's not working for me and I really need this module to work.
Thanks,
Roseline
Montréal, Canada
roseline43@hotmail.com
thanks roseline tried it w
thanks roseline
tried it with a new install of 4.5, but couldn't seem to get it working
i'll have another go tommorrow night to see if i can...
www.justride.co.uk
Have you read this??
Hi,
Youppi!!!!
it's working for me now.
Have you read this thread?
I just discovered that part of the website.
http://drupal.org/node/13142
Roseline43
can't get it working either
I tried installing the sections.module as well with 4.5 and it wouldn't work for me either Roseline. You're not alone.
I'm a newbie, so am unable to decipher or work out why it isn't working.
J
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
Love your site
I cannot comment on your coding, but in terms of design, it looks very clean, and I love how your blocks are not constrained to left and right columns.
--
mediagirl.org
very nice, but how do you...
Just curious -- is there a way with that site to have the menus highlight what section you are in? I mean, if you go to:
http://www.plu.edu/academics/
The button for academics is still the same as the other buttons. It would be nice to disable it and use a different color.
Anyone know if this is possible in Drupal?
-rc
Organizers' Collaborative -- Free Software for Activist Groups
http://organizenow.net and http://organizersdb.org
Template used
Hi strayhand,
I liked very much the layout of your site ( news.plu.edu).
I was wondering if it is possible to provide me with the source of the xtemplate.xtmpl used ?
I am a newbie in Drupal and I am trying to learn how to work with templates. For example, I can't find a way to specify " show me only 3 articles in the left-side of the table" .
I'd appreciate your help
One of the Best!
One of the best Drupal sites I've ever seen!
Congratulations!
Now I need to learn how you did it! I'm going to read everything you wrote very carefully. Thanks for sharing your work!
[]s,
Emiliano.