Search code examples
drupaldrupal-7

How to reference logo image from different nodes in drupal7


I'm doing a job vacancies drupal site which has 2 content types, jobs and company.Company has logo image field.I want to reference company's logo image from jobs node view and show jobs list with view including company logo on home page.I've installed reference module and entity reference module but I dun know how to do it. I can reference company with node reference but I can't reference logo(field in company).

what I want to do is like this image: to use the company's logo on job list view


Solution

  • I had to do this for a project, and I also use the Entity Reference module to do it.

    First : you add a field 'Company', on your 'job' content type, from type "Entity Reference" witch reference the Company content type.

    You add a display "teaser" on the Company content type, that you'll use in your jobs list view. In my case, I use a preprocess_node hook in my template, inspired from a proposal on node.tpl.php reference page :

    <?php
    /**
     * Implements hook_preprocess_node().
     */
    function THEMENAME_preprocess_node(&$vars) {
    
      // Add css class "node--NODETYPE--VIEWMODE" to nodes
      $vars['classes_array'][] = 'node--' . $vars['type'] . '--' . $vars['view_mode'];
    
      // Make "node--NODETYPE--VIEWMODE.tpl.php" templates available for nodes 
      $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
    
    }
    ?>
    

    Then you can define your own template for the Company content type and display (teaser) : node--company--teaser.tpl.php. You'll have to copy the default node.tpl.php template, and to modify it for your purpose (show the logo, use or not the title, ...). You will find some examples and tips on the node.tpl.php reference page.

    After, in your Jobs list view, reference the company field, and select the 'entity view' type with 'teaser' mode.