This is old, but occasionally I run across these threads archived on the net so I figured I'd send out an update

I guess the Search gods were with me today, because I found the answer after 5mins of searching (spent some hours looking last time if I recall).  Anyhow, on this page: http://drupal.org/node/249726  I found this code:

<?php

function phptemplate_preprocess_page(&$variables) {

if  ($node = menu_get_object()) {

    $variables['node'] = $node;

    $suggestions = array();

    $template_filename = 'page';

    $template_filename = $template_filename . '-' . $variables['node']->type;

    $suggestions[] = $template_filename;

    $variables['template_files'] = $suggestions;

   }

}

?>

added it to template.php.  Now when checking the theme developer, I'm getting lovely themeing suggestions like:

page-blog.tpl.php < page.tpl.php

page-service_offering.tpl.php < page.tpl.php

which should allow me to easily theme by content type!


---

brendan, fresh-off.com

Creative Direction & Consultation: Web | Print | Brand

 

http://fresh-off.com

hello@fresh-off.com

206.328.1067

-----Original Message-----
From: themes-bounces@drupal.org [mailto:themes-bounces@drupal.org] On Behalf Of sebastian
Sent: Tuesday, December 01, 2009 10:12 PM
To: A list for theme developers
Subject: Re: [themes] How do i theme blog entries by content type?

Hi Brendan,

I'm planning on putting a tutorial on my blog about how to strip ALL of

the markup that Drupal does to the Views and Panels, so that Drupal can

be changed to produce CSS markup that we want. It is possible that some

Drupal purists will want to kill the CSS purists among us... but I'll

cross that bridge when I get there.

I'm also currently building my new website,. so there isn't a blog to

put my tutorial on [yet]...

I'm a little confused as to why you are not getting better page

descriptions. I just enabled "themer" from Devel on my site to make sure

I wasn't making a lemon, and I do indeed get template suggestions like

the following WHEN I AM USING VIEWS or PANELS:

here is my url:

page/solutions

any my suggested templates are:

Template called:

     page.tpl.php

Candidate template files:

     page-page-solutions.tpl.php < page-page.tpl.php < page.tpl.php

so not the node number... (?)

however, when I use the node view, I DO get a suggestion for the TYPE of

the node:

Template called:

     node.tpl.php

File used:

     modules/node/node.tpl.php

Candidate template files:

     node-page_section_title.tpl.php < node.tpl.php

In my case, page_section_title is the type of node. But make sure you

get a RED box around the node when you click it using themer, if you

click the PAGE level, instead of the NODE level, you will not see these

options... [doh!]

So, I would recommend you theme TYPES and not specific nodes, or theme a

SPECFIC view, or ALL views; if you are using Views. But do NOT theme

just one page; I think that would be a mistake because then you can't

re-use your theme easily on any future pages that may share/use the same

style...

As for pulling that data into a CS variable, you'll need to understand

how to use devel->themer, and how to read variables, and how to use PHP

to access those variables.

Here is an example:

<?php print 'print this variable: ' .   $node->type ?>

put this code either in your page.tpl.php file, or your node.tpl.php

file. It will print to the screen your current node type.

If you wanted this as your class name, you would inject this PHP within

the DIV class's definition:

<div class="<?php print $node->type ?>">

There are obviously lots of other variables you could be extracting to

inject in your CSS, really depends on what you need.

I hope this makes sense, if you can get a grasp on PHP and how to access

the variables, the next step to figuring it out, is to reference:

api.drupal.org

to see all the variables available for a given aspect of Drupal. Knowing

that page.tpl.php and node.tpl.php are your first important starting places.

How to theme Views and Panels involves a different strategy though,

Views has [just to confuse you] more than 3 different ways to theme it,

and Views has only really one way to do it, but you have to set it in

three possible locations, and both methods involve the creation of new

files [either plugin-styles or .info editing, or new tpl.php files]

All of this could, IMHO be a lot easier to understand for someone new to

the game of "power theming" [ie affecting the standard div/class

structure of Drupal]; but that's the way it is. Love it or not.

I think this info should get you going on the right path.

Good luck!

brendan, fresh-off.com wrote:

> *****Thanks for your reply****** S******ebastian******!*

>

> The Path module had previously been installed, and after reading your

> post I installed PathAuto.  But the Theme Developer still isn’t giving

> me any better candidate file choices.

>

> For example, I  have a "Services" page, and using PathAuto have it set

> so that all the sub pages of "Services" to  automatically come out with

> nice URLS (e.g.///// "//////services///////print"/).

>

> But I'm still getting candidates like these:

>

> "*****page-node-2.tpl.php < page-node.tpl.php < page.tpl.php*"   (services)

>

> "*****page-node-72.tpl.php < page-node.tpl.php < page.tpl.php*"

> (services/print)

>

>

> from the Theme Developer.  You also said to make sure I am “linking to

> the page by its human name”  - not sure what you mean.  Pages are linked

> to by human names in my navigation and Path Info,  but its human names

> I’m hoping the Theme Developer will give me for candidate files.

>

> I tried creating a custom content type for all my “Services” pages, but

> that doesn’t seem to have provided any additional candidates.

>

> Regarding your #2 suggestion – I understand the CSS part, but the Drupal

> part is beyond me.  Wouldn’t I need a node variable to appear somewhere

> in the Body tag, or perhaps a “wrapper” div of some sort to make that

> work?

>

> It doesn’t seem like maintaining readable naming conventions for complex

> themes should be this difficult – there must be some basic concept I’m

> missing?

>

> But I’ve been working on it all evening and I’m stuck!

>

> *****Brendan*******

>

> P.S. – I’ll probably try out your theming views suggestion for the blog

> entries.  As for Panels, I was hoping to do all the theming “by hand”

> and keep the markup as concise as possible – but if it keeps taking this

> long, I may have to use the Panels Module…

>

> -----Original Message-----

> From: themes-bounces@drupal.org [mailto:themes-bounces@drupal.org] On

> Behalf Of sebastian

> Sent: Wednesday, November 25, 2009 10:35 AM

> To: A list for theme developers

> Subject: Re: [themes] How do i theme blog entries by content type?

>

> Hi Brendan,

>

> 1. If you are using pathauto, or url names that are more legible than

>

> node/47 etc. then you should also get better theme template suggestions.

>

> Make sure that you are linking to the page by its human-name, not its ID

>

> number.

>

> Some possible other solutions:

>

> 2. User devel to find the $node->type variable, and populate that in one

>

> of your div tags id or class name at a high enough level, that you can

>

> then detect and then theme just that page (or group of pages by type),

>

> this would be done in your main page.tpl.php [and then you don't even

>

> need a separate tpl.php files...]

>

> 3. Use Views to make a blog view that you like, and then you can theme

>

> just that View [with however many 'pages' you make of that view as

>

> daughters]

>

> 4. Use Panels with Views, and then theme on the Panels level.

>

> I'm sure there are others I am forgetting [there is always more than 4

>

> ways to skin a...]




> brendan, fresh-off.com wrote:

>

>>  *Hello Themers!*

>>

>

>>  */How do I theme a page based on content type?/*

>>  I’ve got a site with a few different custom pages and separate .tpl.php

>>  files for their custom layouts and CSS/XHTML.  The “Blog” page is a View

>>  with a list of teasers.  How do I create a custom .tpl.php file that

>>  only targets the “page” (and layout) that the individual/full blog

>>  entries are displayed on?

>

>>  The Theme Developer list these as the candidate files:

>>  *page-node-#.tpl.php *<* **page-node.tpl.php *<* **page.tpl.php.  *

>

>>  But I don’t want to use “page.tpl.php” as its too broad in its reach and

>>  I may decide to add other pages non-blog pages in the future.

>

 

>>  I’ve tried “page-blog.tpl.php” – but it broke my layout.  I still have

>>  some unresolved CSS/XHTML issues, so I’m wondering if

>>  “page-blog.tpl.php” is the correct  naming convention, but  I just have

>>  a few bugs in my code to work out?

>

>>  /A second (less important) question: /

>

>>  Keeping track of all those .tpl.php files is getting confusing!  The

>>  Views pages are easy (“page-blog.tpl.php”  or “page-work.tpl.php”  for

>>  example), but Theme Developer is telling me that for all pages using the

>>  “page” content type, that I have to style them by their ID

>>  (“page-node-1.tpl.php” for the “about” page).  Is there any way to name

>>  a .tpl.php file for a page content type in a more semantic/meaningful

>> way?

>

>>  Such as “page-contact.tpl.php” instead of “page-node-392.tpl.php”

>>

>

>>  Thanks!

>

>>  *brendan, fresh-off.com*

>>  Creative Direction & Consultation: Web | Print | Brand

>>  http://fresh-off.com

>>  hello@fresh-off.com <mailto:hello@fresh-off.com>

>>  206.328.1067

>

>>

>

>>

>

>>

>

>>

>

>>

>

>>

>

>>  ------------------------------------------------------------------------

>

>>

>

>>  _______________________________________________

>

>>  themes mailing list

>

>>  themes@drupal.org

>

>>  http://lists.drupal.org/mailman/listinfo/themes

>

> _______________________________________________

>

> themes mailing list

>

> themes@drupal.org

>

> http://lists.drupal.org/mailman/listinfo/themes

>

>

> ------------------------------------------------------------------------

>

> _______________________________________________

> themes mailing list

> themes@drupal.org

> http://lists.drupal.org/mailman/listinfo/themes

_______________________________________________

themes mailing list

themes@drupal.org

http://lists.drupal.org/mailman/listinfo/themes