I've been searching and cannot find a way to achieve this: display content referencing a content that is referenced by the content being displayed.

It may be somewhat confusing but I'll do my best to be clear:

I have two content types: 'Company' and 'Service' As you can imagine a Company provides many Services, so there is an Entity Reference field in Services that points to the Company providing it.

That's it: Service content points to Company content in a many to one relation, many services point to one company (the company that provides them)

When I display a Service, I also display the company that provides it through the Entity Reference field.

Now the tricky part is: When displaying the page for a Service, I'd like to also show (e.g. in a sidebar) the other services provided by the Company that the displayed Service is pointing to.

I'm using Panels and Views on Drupal 7.

Please note: this is not a simple 'related content block', that's what I am using to display the company providing the content or when displaying the Company content

1 Answer 1


I don't see any problem here. or any difficulties to do this.. You only need a block with services of certain company, so you can create a views block , pass company id as argument (by contexual filter), and exclude current service from it.. But, I don't think that simply assigning it to region can help you, because you will need to fetch company id from service page and pass it to view block. I think the solution will be to implement hook_block_info and hook_block_view hooks to create another block and fetch company id from service page and display it..


function MYMODULE_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'company_service':
        // there is multiple ways to get field value from entity. In this example I am it getting with entity_metadata_wrapper function from Entity API:

        $service_node = menu_get_object();
        $service_wrapper = entity_metadata_wrapper('node', $service_node);

        $company_id = $service_wrapper->field_company->value(); // I don't know the structure of your entity fields, that's why we assume that $service_wrapper->field_company->value() will get company_id..

        $block['subject'] = t('Company services');
        $block['content'] = views_embed_view(VIEW_NAME, DISPLAY, $company_id);
  return $block;
  • Hi xurshid29, yes your approach seems it will work fine, although I was trying to solve it just from the admin interface without coding, I'll give it a try. Aug 28, 2014 at 7:13

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.