Module Monday: Similar By References

List related content easily through Entity Reference fields

Building a block that lists content related to the current node is a common requirement on any website. If you are viewing the details of a book, it may come handy to see a list of similar books at the bottom of the page. Depending on the Architecture, there are several modules that support this. This time we will cover Similar By References module.

Similar By References comes with a Views block display that finds matches based on Entity Reference fields of the node being viewed. After installing it, we can navigate to Structure > Views and edit the Similar By References view.















Similar By References - Views block

The default settings provided by the module are normally good enough for most of the cases but, at the very least, we need to edit the Contextual Filter at the Advanced section of the Views block in order to define which fields should the module use to find related content. For example, the MSNBC website used this module to find related content for a given article based on the Issues and Topics fields. Here we can see how it was configured:















Similar By References - choosing fields to match

Once we have saved our changes, we can add the block to the node layout just like any other block. This step would vary depending on which engine you are using to manage your front end layout - Drupal core's block system, Context module, Panels module or Display Suite module. Simply add the Views block wherever you want it to appear. Here we can see the final result at an article's full display:















Similar By References example

We found out that on websites with a huge amount of content, the database queries that the module builds are very slow. We encountered ourselves with this issue and you can find out our conclusions at this article.

Overall, and despite the potential performance impact mentioned above, the module works great and with practically no coding at all you can build really neat listings of related content. Now go and checkout Similar By References module.

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!