How To Create 'Node 1 vs Node 2' 'Node 1 vs Node 3' nodes etc as quickly as possible to compare their fields? I want to create a node for each comparison of 2 nodes, so you end up with site.com/node-1-vs-node-2 and then on that page it shows both the node 1 and node 2 fields side by side in a table to compare them.

What am i looking at to get this done as quickly as possible? I have 50 nodes in total and want to do node 1 vs node 2, node 1 vs node 3, node 1 vs node 4, etc all the way through.

Would it be views, or entity reference which shows a table format for each output?

I'm using Drupal 8
You could achieve this quite easily with a custom module. In this example I'll use Drupal console to simplify settings every thing up.


Create a module:

drupal generate:module


Call it whatever you want.


Create a controller:

drupal generate:controller


Sample answers for this may be:


Controller class name: ComparisonController
Method title: CompareNodes
Action method name: compare_nodes
Route path: test/compare_nodes/{id1}/{id2}


Now edit your newly created controller. At the top add a use for the node module:

use Drupal\node\Entity\Node;



Edit the compare_nodes method.


Here is some sample code:

public function compare_nodes($id1, $id2) {

  $node1 = Node::load($id1);
  $node2 = Node::load($id2);

  $fields_to_compare = ['body'];

  $build = [];

  foreach($fields_to_compare as $field) {
    $build['comparisons'][$field] = [
      '#type' =&gt; 'container',
    ];
    $build['comparisons'][$field]['value1'] = [
      '#markup' =&gt; 'Node 1 value: ' . $node1-&gt;get($field)-&gt;value,
      '#prefix' =&gt; '&lt;div&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];
    $build['comparisons'][$field]['value2'] = [
      '#markup' =&gt; 'Node 2 value: ' . $node2-&gt;get($field)-&gt;value,
      '#prefix' =&gt; '&lt;div&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];

  }

  return $build;

}


You can edit the list of fields to compare as required and also make any changes to the markup required.

Enable your module and now when you visit: /test/compare_nodes/1/2 you can compare the values of node 1 with node 2.

You can replace 1 and 2 with whatever ids you would like to compare.