I got product collection in my custom template using following code
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
foreach ($productCollection as $product) {
$product_id=$product['entity_id'];
echo $_product->getName();
}?>