Another way to relink nodes in Drupal 7

So the task is the following - there is a type of content, for example, a product, and we need to link other products to some product cards, under the guise of components, in the admin panel. At the same time, on the product page, display a list of components, and on the product-component page, display a list of the product for which it is used by the component.

To begin with, we add the Entity Link field with auto-completion for the product and the target package of the content type of our products. Through this field in the adink, we will choose which products we need to link to the original product as components.

I think few people use stock theme templates and further description will be more focused on collective farm custom templates.

To display directly component goods of the original product, we create a view with output to the goods block. Choose the format that you like best, in the links select the link "Reference to the entity: Referring entity. Bridge to the entity Content, which refers to the Content through field_name", where field_name is the name of our added field. And in the context filters we select Content: Nid, in the filter links we select our previous link, we pass the default value of the material ID from the URL.

The view has been created and we need to display it in the node template. We do it with a small line in php

$spare_ithem = views_embed_view('spare_ithem', 'block');
echo render($spare_ithem);

where spare_ithem is the machine name of our view.

Thus, we posted a list of its components at the product.

To display on the page a complete list of goods to which it is linked, we create the same view, but in the connection we select "Reference to the entity: Related entity. Bridge to the Content entity, which is linked through field_name".

And then we already display the view in the same way anywhere in the template node, specifying the machine name of the second view.

 

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.