Special design for special content type node

Discussion in 'Drupal' started by s_ruben, Jun 5, 2011.

  1. #1
    Hi,

    I want to know which file to create to display special design for the special content type nodes for D7. For example I created a content type "General Content" and machine name is "general_content" and I want to change the design of the nodes pages which content type is "General Content". I tried to create page--general_content.tmp.php and node--general_content.tmp.php, I cleared all caches from admin/config/development/performance but the special page doesn't display. Please help.

    Thank you.
     
    s_ruben, Jun 5, 2011 IP
  2. cjscully

    cjscully Active Member

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    If you're using two hyphens in the template title "page--" or "node--" that's your problem. there should only be one.
     
    cjscully, Jun 7, 2011 IP
  3. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #3
    Thank you for your reply. I changed 2 hyphens to 1, clear all caches and then go to the page of node (like http://mydomain.com/emergency) which content type is "general_content" and it shows empty page as there are only php comments in the page.tpl.php file. I am creating a theme which is subtheme of zen. Maybe I have to do something else.
     
    s_ruben, Jun 7, 2011 IP
  4. cjscully

    cjscully Active Member

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    Sorry. I should know better than to answer questions late at night when I'm not fully awake. The single hyphen is the D6 format. Double hyphen is the D7 format. I've done a few sub-themes and here is all I needed to do:
    1. Copy the target template from the main theme folder to my sub-theme folder.
    2. Rename it to page--special_page.tpl.php in my sub-theme folder.
    3. Make the changes I want to make to it.
    4. Save it.
    5. Make sure permissions are set correctly on the server.

    For me 3/4 of the empty page problems I've ever had working with Drupal themes have been due to incorrectly set permissions. The rest have been due to typos or omitted semi-colons in my PHP.
     
    cjscully, Jun 7, 2011 IP
  5. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #5
    cjscully,

    Thank you again, but here is what I want: I have different content types and I want to display different styled pages for different nodes depends on the content type of the node. I mean if I go to a node page which content type is "General Content" I see a page styled just for the content type "General Content".

    Thank you.
     
    s_ruben, Jun 7, 2011 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    I just add this into template.php

    
    <?php
    function siteTheme_preprocess_page(&$vars, $hook) {
    	global $CCK;
    
    	$frontPage = drupal_is_front_page();
    	if (isset($vars['node']) && $frontPage != 1) {
    		$vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
    	}
    
    	// Define CCK Field variables and unset the existing ones
    	// All page--contentType templates that use these variables must
    	// first declare global $CCK;
    	if (isset($vars['node']))
    	{
    		foreach($vars['node'] as $key => $value)
    		{
    			if (strpos($key, "field_") === 0)
    			{
    				// If there the value is an array
    				if (sizeof($value['und']) > 1)
    				{
    					foreach ($value['und'] as $innerKey => $value)
    					{
    						// Store either the value or the tid
    						if ($value['value']) { $CCK[$key][] = $value['value']; } else
    						if ($value['tid']) { $CCK[$key][] = $value['tid']; }
    					}
    				// Else if 1 item
    				} else { $CCK[$key] = $value['und'][0]['value']; }
    			}
    		}
    		// Unset the $vars['node'] entry to free up memory
    		unset($vars['node']);
    	}
    }
    ?>
    
    PHP:
    and created page--contenttype.tpl.php file in which I added my code for the node by content type "contenttype". I only didn't understand why it didn't work with content type which machine names has a underline in it.

    Anyway, thank you all who wanted to solve my problem.
     
    s_ruben, Jun 8, 2011 IP