Hi all,
I have posted this in the themes section but maybe that was the wrong place as I am getting no replies...so perhaps this will be a better place to post this question:)
I have different sections for my site and want each section front (& section page) to have their own slightly different look (I have assigned a different slightly modified template to each one.) I also want a few static pages to have their own look (again, just a slightly modified version of the main template)
The static pages work just perfectly but the "Views page" (the page that has been brought together w the views module) is not pulling in the correct template, although once you click through to each individual node from the "Views page", each node DOES pull up the correct template. I am completely baffled at why I cannot get this to work!!
I am using the method at this link http://drupal.org/node/46027 (Customising the full page layout and sections based on path)
Here is the code I am using so that the proper templates are called per section page:
<?php
function phptemplate_preprocess_page(&$vars) {
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$suggestions = array();
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}
}
if (drupal_is_front_page()) {
$suggestions[] = 'page-front';
}
$vars['template_files'] = $suggestions;
}
}
?>
So far I have the following (on my local server):
page-about.tpl.php template for an "About Us" static page that I created (via Create Content>Page)
The URL for this page is at "http://www.mysite.com/about"
When I go to that page it pulls in the proper template
page-articles.tpl.php template for an "articles" page that is brought together using Views
The URL for this page is at "http://www.mysite.com/articles"
When I go to that URL, the page-articles.tpl.php is not being pulled in....the regular page.tpl.php is being used instead.
Whereas, if I create a static page thru create content>page with the URL of "http://www.mysite.com/articles" then the correct page-articles.tpl.php is pulled in.
Do you think that Pathauto may be causing the problem or is there anything else you can recommend?
(For background, here is one of my earlier posts before I used Views to pull in the content for the Articles page : http://drupal.org/node/284974#comment-930062)
Thanks very much in advance for your help!
Christine
Comments
UPDATE...the plot thickens...
I tried using code that was suggested here: http://yubastudios.com/blog/drupal-extending-templating
When I use this code (pasted below), then things work in reverse to how they do when I use the code that I referred to in my original post above. I am baffled! Let me explain further:
If I use this code below, then only the "Views" page at http://www.mysite.com/articles displays with the correct template but when you click on the individual nodes on that page, then each of those node pages comes up using the incorrect page.tpl.php template! (for example, http://www.mysite.com/articles/article1 will display with the incorrect template)
If I use THIS code however, below, then only the individual nodes show up using the correct template but not the "Views" page, which uses the incorrect page.tpl.php template. Can you help me make sense out of this? And is there a way of combining the two so that both the views at http://www.mysite.com/articles AND the nodes themselves http://www.mysite.com/articles/article1, etc.
Could you post the output
Could you post the output of
for yoursite.com/about, yoursite.com/articles, and yoursite.com/articles/some-node ?
(for the phptemplate_preprocess_page function, using the first block of code you posted)
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
Here we go:
Yuriy,
I sincerely apologise (to everyone) for all these posts! The first post was because I was replying to someone else's post (Brian's...that other gent you are helping) and I thought it would be a preferred solution to start a new post instead of creating a whole new issue inside someone else's post.
The second duplicate was a mistake because I could not remember where I had posted it and so reposted it...then I just started to update the posts I had already. I am NOT usually this scatterbrained... I did this in a rush while I was at work trying to keep to my usual deadlines...
Anyway... back to business:
If I go to mysite.com/about (the static page) here is the output:
mysite.com/articles/some-node:
mysite.com/articles
There is no output!
The above results are what I get when I use this code:
When I use the code below, I get NO output at any of the pages.
Going to mysite.com/articles (the Views page) brings up the correct page-articles.tpl.php but mysite.com/articles/some-node brings up the incorrect page.tpl.php AND going to the static mysite.com/about now also brings up the incorrect page.tpl.php instead of page-about.tpl.php.
I wonder if pathauto is interfering w anything here?
OK, lets keep all discussion
OK, lets keep all discussion in here: http://drupal.org/node/285416
It's hard jumping between two threads...
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
I will recreate it live....will be done in just a few moments
I had been doing this all on a local testing server
The "code below" you posted
The "code below" you posted does not contain a
phptemplate_preprocess_page()function, so that's one of the reasons why you're not getting the correct page-template. Template suggestions are being set for blocks and nodes, but not pages. Add this function (you can even use the one above - first snippet of code you posted) and everything should work fine.Path auto should not be causing problem; I always use it (along with Views, and the code I posted) when I create a Drupal sites.
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
Here is the code ...added the part about the pages but still no
luck:(
I am having success with mysite.com/articles but no luck with mysite.com/articles/some-node
Here is the code I am using... I also don't understand why I am not getting output:(
I am going to recreate this live in just a bit...have to go run an errand. Yuriy...thank you so much! I really appreciate your help with this.
The site is at http://74.220.215.68/~leemagaz/
I need to install the modules over there and the content type articles in order to recreate it(I have just started building it so the domain name hasn't even been transferred over yet)
Forgive me for asking this question that must seem so very basic to you...
I do not work w php code at all alas:( (Altho' I want to start learning some in the very near future...)
Okay... here it is live...
That took MUCH longer than I thought due to some unforseen issues, such as php mem limit for example....had to find out how to increase it on the server but got that sorted out.
Go to http://74.220.215.68/~leemagaz/article to view the article page and then click on the article as well....
Forgive me for stating the obvious but . . .
You've done some nice work there, Christine (your prototype site in your other post). However, while Yuriy's code is extremely useful and I can't help but admire your persistance with it, I'm wondering if you've considered simpler solutions?
I assume you checked out the Drupal 6 (or Drupal 5) theming handbook pages? There's already considerable flexibility in Drupal's default template files to theme specific pages without having to muck about with coding the template.php file. There's one trap that might pertinent in your case: Drupal looks at a page's internal system URL for the template file rather than the page's URL alias.
It's easier still to base your theme on the Zen theme. It's well documented both in the code and on the Drupal site. Particularly nice is the way it creates an individual CSS class for every page. For example, for your Views article page, it would create a .view view-article class, or something like that (the Firefox Web Developer toolbar will tell you for sure). This means you can individually theme every element on that page by just adding to your CSS file. Check out this podcast for more info.
If you only want to do something simple like drop a column, you may not have to do any coding at all. The simplest solution is to configure blocks (changing the page-specific visibility settings), so that all blocks in one particular column are disabled on certain pages or sections. As most good themes support collapsible regions, that's what happens to the column without any blocks -- it collapses.
Forgive me if you've already tried these techniques and I'm stating the obvious, but being relatively new to Drupal myself, I know what it's like to be overwhelmed by Drupal's many different options, which makes easy to overlook the simplest solutions.
Posted possible solution
Posted a possible solution for Christine here in the other thread: http://drupal.org/node/278181#comment-931466
Just letting people in this thread know so no one duplicates efforts if unneeded. If anyone has been solutions though feel free to post them.
As I mentioned in the other thread, I think this isn't the best approach (multiple page.tpl.php versions), as some simple CSS could handle things quite easily if you make use of a section/page based ID and/or Class in the
<body>.-- David
absolutecross.com
Thanks Glennr:)
I will work some more w the Zen theme in the future. I did use it for my personal website (based it on the Zen theme). For Lee Magazine I felt it was easier to convert the static over instead of starting w the Zen theme. The live site of the Lee Mag website (still under construction and has a longway to go) is at http://74.220.215.68/~leemagaz/
I did not know that the Zen theme was able to create additional CSS classes on the fly like that....that is VERY nice to know:)
I have very recently started going thru the handbooks...decided I need to do more of that instead of constantly harassing everyone with a zillion questions:)
Have a wonderful day!
Christine