I'm a little new. I need to create a view for related content between different content types, some have same taxonomies field other no. It is a multi language site. So, the view was a little complex, then I am trying with EntityQuery. This search needs to be updated each time that the user update a taxonomy

How can I present the result of my entity query in a node? in a custom block? where can I put my code ?

I asking for a structure or a way to do it this.

2 Answers 2


How I solved my issue with this structure.

I created a manager here my_module/scr/Pluging/myManager.php

Here I have a function with a entityQuery that return a list of nodes.

I created a block here my_module/scr/Pluging/Block/myBlock.php

Here in my build function a call my function in myManager.php and I pass the name of the theme, and a variable with my list of nodes

I updated my .module here my_module/my_module.module

In hook function my_module_theme() I add my theme and varibles to be pass.

I created a twig here my_module/templates/block-related.html.twig

Here I just do a for to display all field of each node.

Then in my admin/stucture/block I added my block to display in Content section in specific content type.


IMO, the best way to handle related content is for the content admins to manually associate related nodes via a content reference field. There are probably many ways to programmatically relate content, but nothing will be as reliable and accurate as a human making the content relations.

All you need really is a couple nodes associated with each piece of content, then you can drill down as far as you need through related products in your view...

I'll admit this approach may not be feasible for sites that already have a lot of content. But if you are starting off, I feel you should start off this way if you need related content. Just associate some related nodes every time you create a new piece of content.

Then you would create a views block, and show that block on your node.

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.