简体   繁体   中英

Drupal - custom region in custom content type

I'm having big troubles at displaying blocks on a custom content page only.

So here's the problem; I have block X that I want to display on a node that is of a custom content type Y. I do not want this block to show on every page, only those that are of a given content type.

If I define custom region Z on my custom content page template (eg. Y.tpl.php) I can't print region contents on there ($Z) since the variable appears to be empty. If I define that very same region on a page.tpl.php i can print region contents with no problem.

So I think the problem is that the region variable ($Z) is not passed on custom content page. Is there any way i can achieve this behavior?

Using a special region displayed on your content type page is not an clean solution to display a block only for nodes of a specific content type. The block will still be rendered in memory by Drupal for every pages. Instead, you may want to control the visibility of the block with some PHP code using menu_get_object( ) to get the current node and its type.

$node = menu_get_object();
return $node && $node->type == 'custom-content-type';

Should display the block on any /node/$uid and /node/$uid/* pages. To avoid displaying the block on /node/$uid/* pages, the following should work

$node = menu_get_object();
return $node && $node->type == 'custom-content-type' && !arg(2);

You can do this with Context -> http://drupal.org/project/context

Because the page you want the block in has a path, node/%nid or clean url, you can set the context to show the specific block in a region you want for only that path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM