0

It's fairly simple to display a block on the node add form for a particular content type. Simply restrict visibility to a URL path like node/add/article and you're good to go.

I would like to know how to display a block on the edit form for a particular content type. For instance, when editing an article, the URL path is node/NID/edit.

Is there an easy way to display a block for edits of a given content type?

  • You need to use php code to implement this. – Jayendra Kainthola Dec 18 '13 at 6:17
  • Do you have an example of a snippet I could put into the PHP code textarea to accomplish this? – DeepFriedBits Dec 18 '13 at 6:18
2

You need to add php code in the block Visibility settings in admin section of block. You can follow below code.

$node = menu_get_object();

   if (isset($node) && $node->type == 'article' && arg(2) == 'edit') {

     return TRUE;
   }

   return FALSE

Another example:

$nid = arg(1);

   $node = node_load($nid);

   if (isset($node) && $node->type == 'article' && arg(2) == 'edit') {

     return TRUE;
   }

   return FALSE
1

Here's how to display a block on an add and edit form for a particular content type via PHP code in the block configuration.

<?php
    $show_block = false;
    $content_type = 'article';
    $types = array($content_type);

    if (arg(0) == 'node' && is_numeric(arg(1))) {
        $nid = arg(1);
        $node = node_load($nid);
        $type = $node->type;
        $show_block |= in_array($type, $types);
    } else if (arg(0) == 'node' && arg(2) == $content_type) {
        $show_block = true;   
    }
    return $show_block;
?>

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.