Embedding a view inside a node template
Views usually tend to be output as pages, blocks, and other displays. In this recipe, we will be looking at taking this a step further by manually embedding a view inside a node template using a smidgeon of code. To be more precise, we will be taking the backlinks view which comes with the Views module and embedding it inside a theme's node template file to provide a list of related content which links to the node currently being displayed.
Backlinks provide a list of nodes which link to the current node. For example, if in the content of node/123
, we include a link to node/456, node/123
is considered to be a backlink of node/456
.
Getting ready
Since we are going to be embedding the backlinks view, it is assumed that it has been enabled. Additionally, for backlinks to be available, the content of the site will need to link to each other. In other words, sample nodes will need to be created which link to other nodes in the site to allow backlinks to be...