Lets say I have a Company content type that contains the following fields:

  • Company Name
  • Company Description
  • Company Logo Image
  • Company Website URL

I use the Entity Reference module to relate companies to Articles. When displaying an article page I would like to show the company logo which should link to the URL with the description on-hover. If I were using a view I'd do a rewrite for something like this:

<a href="[Company-Website-URL]">[Company-Logo-Image]</a>
<div class="tooltip">[Company-Description]</div>

How could I do something similar for the actual individual article page?

  • 1
    Can you clarify which content type the Entity Reference field is on. Is it on the company or the article? Commented Jan 6, 2013 at 1:40
  • The article has a reference to company.
    – kscott
    Commented Jan 6, 2013 at 18:34

2 Answers 2


I assume you have an entity reference field "Company" in the content type "Article". You could implement hook_node_view() to achieve this on the individual article node page. Check the following example code:

function mymodule_node_view($node, $view_mode = 'full', $langcode = NULL) {
    if($view_mode == 'full'){       
        if( $node->type == 'article' ){
            // load the entity reference 'company' in full
            $company = node_load($node->field_company[LANGUAGE_NONE][0]['target_id']);

            $logo        = $company->field_logo[LANGUAGE_NONE][0]['uri'];
            $logo        = '<img src="'.file_create_url($logo).'" />';
            $website     = $company->field_website[LANGUAGE_NONE][0]['safe_value'];
            $description = $company->body[LANGUAGE_NONE][0]['safe_value'];
            // delete the default entity reference display
            // add the company logo to the node view
            $node->content['logo'] = array(
                '#markup' => l($logo, $website, array('html'=>TRUE))                
            // add the company description to the node view
            $node->content['tooltip'] = array(
                '#markup' => '<div class="tooltip">'.$description.'</div>'


API reference for functions used in the hook.

  • Since the OP is asking for, "the actual individual article page," this is the correct answer. The Views module shows a list of nodes, but not single nodes.
    – apaderno
    Commented Jan 6, 2013 at 10:22

You should use Views module for that.
1 - let's create new view (show: content, type: company)

2- we want to create block not a page display, then press "continue & edit".

3- now add the three fields (Company Logo Image,Company Website URL,Company Description) but you should exclude them from display, yes all of them.

don't forget to delete the title field or exclude it from display too.

4- add (Global: custom test) field and uncheck (create a label), in the text field you can use "REPLACEMENT PATTERNS" to recreate what you want exactly, like this:

<a href="[Company-Website-URL]">[Company-Logo-Image]</a>
<div class="tooltip">[Company-Description]</div>

when you finish click save.

5- now you have to add a "CONTEXTUAL FILTERS", search for the Reference field you
added to your content type, in (WHEN THE FILTER VALUE IS NOT AVAILABLE) section select "Provide default value" then select from the type list "Content ID from URL" and save the field and the views too.

Finally you should display the view in the node page, so you can do this by two ways:
A- using display suite module you can add this view as dynamic field and put it it the region you want.

B- by php code (you can use computed field module to write php code in a field)

$viewname = 'YOUR_VIEW_NAME';
$display = 'VIEWS_DISPALY';
print views_embed_view($viewname, $display);

you should notice you can get the Your view machine name ($viewname ) from the url while you are editing the view setting:

and the display of you view:

if you need any help just tell me.

  • The OP is asking for the individual article page, which I get as an Article node when viewed alone. The Views module shows a list of nodes, not the single nodes.
    – apaderno
    Commented Jan 6, 2013 at 10:20

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.