8 – Cannot access variables on twig from preprocessing functions


I am using a preprocess function to get data from specific content types. I can print the data in the preprocess function but I can't see it in the twig file.

Here is my preprocess function.

    function themename_preprocess_node__custom_content_type_name(&$variables) {

      $query = Drupal::entityTypeManager()->getStorage('node')->getQuery();

      // Get all products node IDs.
      $nids = $query->condition('type', 'content_type_products')->execute();

      // Load all product nodes.
      $nodes = DrupalnodeEntityNode::loadMultiple($nids);

      // Pass them to node--custom-content-type-name.html.twig.
      $variables('products') = $nodes;

     //echo "
";
     //print_r($variables('products')); exit;
    }

I can see the values ​​here, if I print the $variables('products'), but when the twig file is passed node--custom-content-type-name.html.twig' as{{products}} `I can't see anything.

Did I miss something here? Any help is appreciated.