2

I'm new to drupal and coding so I'll try and explain best I can the issue I'm having.

I'm on Drupal 7, using Zen Sub Theme

I have a site which is essentially a database of gadgets. 'gadget' is a custom content type with custom fields such as 'year of manufacture', 'manufacturer', 'image' and 'description'.

I work out of 'page.tpl.php' to control the look of my homepage. I find this to be very easy to use, as far as creating/formatting regions. Essentially formatting the building blocks of my template. On the homepage I have list of links (created via views) to the most recent gadgets. When I click on a gadget it takes me to the 'Gadget' page displaying all the fields I mentioned above.

Now to the issue I'm having:

I can't figure out for the sake of me how I can have a tpl file for the custom content type (ie. the gadget). I have so far formatted the page with CSS but it would be nice if I can have (I prefer to work through editing the tpl files) a TPL file for the page elements (ie. header, footer) and a TPL file for the region its showing my gadget node.

I've attached a picture of what I'm trying to do:


The home page templating

http://imageshack.us/photo/my-images/402/homepagem.png/


The gadget page templating

http://imageshack.us/photo/my-images/560/pageinside.png/


What I've tried:

1) Formatting the gadget page with CSS : This works fine, but I would prefer to have control over tpl file.

2) In the templates folder I added node--gadget.tpl.php and cleared cache (doesnt work). node.tpl.php on the other hand does get pulled up by static pages in the site (like the 'about us' page) but not on custom content type (gadget).

3) I added the code below to confirm that content '[type] => gadget':

    <?php
function gadgettheme_preprocess_page(&$vars) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $tid = arg(2);
    $vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
    $vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $vid;
  }
}
?>

4) Finally I put in the code below and create a page--gadget.tpl.php. This worked but the problem is its page--gadget controls the whole content which means I would need to copy over the template from the page.tpl.php to control the header and footer. I want these elements to be controlled solely from page.tpl.php and have another node--gadget.tpl.php.

function gadgettheme_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

?>

Your help is appreciated in advance,

Cheers,

2

I've managed to solve this issue.

I was using display suite to format my node and without realising I was using the Display Suite's theming file. Once I renamed my node--gadget.tpl.php to the Display Suites theme name ds-1col--node--gadget.tpl.php it worked!

Cheers,

0

Since you say you're new to drupal, I hope you don't mind some simple questions?

  1. IF the machine name of your content type is "gadget" then your point #2 should work. The fact it isn't begs my questions about your presumptions about drupal subthemes. SO:
  2. Where does you subtheme directory exist?
  3. What is the name of your subdirectory?
  4. where is your "templates" subdirectory?

NOW with THAT out of the way, I strongly suggest you check out "Display Suite" which gives you enough output customization to make any themer happy. http://drupal.org/project/ds You can customize your node output within the Drupal UI and with a bevy of handy options for full node view, teaser view, and any custom view you'd like to create.

Regardless, let's make certain your subtheme is correctly established.

  • 1) Yes.. this is what I was hoping. 2) site > all > contrib > gadgetweb (copied from zen STARTER KIT folder) 3)css, images, images-source, js, sass, sass-extensions, templates 4)as shown in 3) Thanks Kyle, I'll check out Display Suite. Although I have themed the page the way I want it to look, I would still like to get this tpl method working if possible. Thanks in advance. – dangerranger Apr 19 '13 at 14:22
  • Also, just to confirm the sub theme does work. The page.tpl.php is picked up (residing in subtheme>templates folder), however nodes--gadget.tpl.php is not. Cheers – dangerranger Apr 19 '13 at 14:30
  • Hrm. Let's be pedantic about paths: while "contrib" might work, I wouldn't use that convention. I'd try moving my subtheme to sites/all/themes/gadgetweb is where I'd put my subtheme. I presume sites/all/themes is present already? Where is your zen base theme located? Also: please confirm that the machine name for the gadget content type IS "gadget" You can do this on the content type page at "admin/structure/types" Finally, zen + drush is excellent for creating subthemes. Read the "drush support" on the zen page for more info – Screenack Apr 19 '13 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.