To add custom text to a node I have a code like this:

function mymodule_node_view($node, $view_mode, $langcode) {
  if (.....) ){
      $node->content['new'] = array(
       '#markup' => $var,

It works perfectly, but now I need to add this text to pages that don't load any node. So I can't use this hook.

I mean something like the drupal_set_message function, showing custom text at the top of certain pages.


3 Answers 3


maybe you can add this to your if condition:

if($view_mode == 'full' && node_is_page($node)){
   //your code here
  • When I access pages that don't load any node (that is where I need show the text), the hook I am using (hook_node_view()) doesn't execute, so your solution is not working.
    – Alfonso_MA
    Commented Sep 8, 2013 at 1:37

Have you tried adding your text inside a block, then assigning it to a region? Context is useful for assigning blocks to regions based on a variety of conditions.

  • My text changes depending the page you access, so I think I can't use a block to do that. Can I?
    – Alfonso_MA
    Commented Sep 8, 2013 at 12:07
  • You can: One of the conditions the module has is the path of the page being shown.
    – apaderno
    Commented Jan 24, 2016 at 6:09

I would use panels and panels everywhere for that. You can actually just create custom text panes and add to any page.

To get started with these two modules I can recommend the videos by cojanti

Block and Context as mentioned above is also possible but we never use that since blocks are not deployable so easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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