Drupal 7: How to theme nodes based on region? - drupal

How do I control the output of a node rendered inside a specific region?
Inside Sidebar First, I can theme blocks by creating a block--sidebar-first.tpl.php template file. However, creating a node--sidebar-first.tpl.php does not work.

Unfortunately, Drupal doesn't have support to have node template based on region. You can check out this link.
If you want to achieve your goal you can use Display Suite module. Here are some screen-casts about how to control your content with Display Suite. Here's also a comment about this.

For theming a node first thing you need a custom node template file.
Inorder to do that copy your node.tpl.php and rename it as node-[ur_node_name].tpl.php .
Now you have created a custom node template. In case of blog entry my node name would be node-blog.tpl.php [Drupal-6] and it would be node--blog.tpl.php [Drupal-7].
NOTE:
Make sure the [ur_node_name] part is the machine readable name.Now in your new node template give your corresponding styles and print the contents of the node.This is how you theme a node.Hope this helps you... :)

Related

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Drupal 7 Adding Page with different template of page

I am not experience, can smbd show the way. I need give possibility to simple user to create Page and he need to have possibility in select area choose Templates type for the page which he is create. How to do it?
I suggest you create multiple Content Types and give them the names of the templates you want to offer.
Then, you'll need to create those templates, you should probably use node.tpl.php as a base.
After you're done with a template you can save it in the templates folder (/sites/all/themes/[THEME_NAME]/templates/) and name it like node--mycontenttype.tpl.php
Note that you'll need two dashes (--) after the word node in the filename. For more information on designing templates for Drupal, please refer to https://www.drupal.org/documentation/theme

What is Drupal Panel Node Template

What is Drupal Panel Node Template and how can i use it to create a page based on person type node.
Also is there any tutorial on creating pages using Panel Node Template.
Thank you.
Probably you don't need to use a node panel. What you want to do is edit the node template for the content type you want to customize instead.
There is extensive documentation in http://drupal.org/project/panels

How do I display individual fields in a custom block?

A have a view created with Drupal's Views module, and have given it a Block display. It has the following fields:
first_name
last_name
professional_title
I understand that I can create a "[viewname]-block.tpl.php" file to provide a custom theme for this particular block, overriding the generic block.tpl.php template file. Within this [viewname]-block.tpl.php file, how can I pull out individual fields (eg, First name) so that I may theme them individually, giving them different classes? I've taken a look at $block, which yields $block-content, containing all fields, but this is as granular as I have managed to go so far.
Any help is appreciated.
Go into the Views UI and navigate to the block view you're trying to theme.
Under basic settings (at the bottom of it in fact) you'll see a Theme Information link. Click it.
I'm copying and pasting the official description of what that does:
"This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold."
So find the template for the field you want to theme and click the link for it - you'll get code to copy and paste. The code will be really generic, but there are notes in the generated tpl file about how to pull more specific object data.
Hope that helps

Drupal 6: Drupal Themer gives same candidate name for different type of content types

I'm a drupal newbie...
I have different type of contents like News, Events, etc. and their content is different. News detail page has title-content text-date. but Events detail page has title-date-content text-location-speaker-etc. So I need different layout page for these different types. So, I enabled Drupal Themer to get a candidate name. for events page, it gave me page-node.tpl.php and it gives same for News page as well :( how can I separate these pages? I expected sth like page-event-node.tpl , but no... :/ Drupal Themer also give unique candidate name for event page like page-node-18.tpl.php but it doesnt mean anything since I can not create a general layout for all events by this node name. :(
Appreciate helps so much!! Thanks a lot!!!
While using different node.tpl.php files as suggested by monkeyninja (+1) would be the 'normal' way, you could add the functionality you want by adding page template suggestions based on node type yourself, in a preprocess_page function within a custom module/theme:
function yourModuleOrTheme_preprocess_page(&$variables) {
// If this is a node page, add a page template suggestion based on node type
if (isset($variables['node'])) {
// Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
$suggestion = 'page-type-' . $variables['node']->type;
// Add to end of suggestion array, thus keeping the fallback to other suggestions,
// if this specific version is not implemented by the theme
$variables['template_files'][] = $suggestion;
}
}
With this in place, you should be able to add e.g. a 'page-type-event.tpl.php' file, which should be used for all event node pages.
(NOTE: You'll need to trigger a rebuild of the theme registry after adding that function to get it recognized by the system)
I'm not familiar with Drupal Themer, but a slightly different approach would be to work with the node templates to style the content and use something like the excellent Context module (and possibly Panels module) to change the layout of any additional information on the page (eg the blocks).
To theme the different content types using node templates, just create templates based on node.tpl.php in the form node-content_type.tpl.php. So you'd have a template for your events nodes called node-events.tpl.php.
You could then define a context using the Context module that reacted when a page of the events content type was displayed and select which regions/blocks you wanted displayed.

Resources