Listing downloads for a product

A product may have any number of downloads. Many merchants like to offer PDF downloads such as instruction manuals, installation instructions or care guides.

All downloads for a product are accessible via the Product.downloads() method which returns an Array of ProductDownload objects.

<ul>
<?ev for (var download of product.downloads()) { ?>
    <li>
        <a href="{{ download.url }}" target="_blank">
            {{ download.title }}
            <br>
            {{ download.filename }}
            <br>
            {{ download.size }}
        </a>
    </li>
<?ev } ?>
</ul>


Handling missing files

In a perfect World things wouldn't go missing. Sadly, they do. Downloads might have been deleted or imported incorrectly. You can determine if a product download's file exists with the ProductDownload.exists() method.

<ul>
<?ev 
    for (var download of product.downloads()) { 
    
        // Skip missing downloads
        if (!download.exists()) {
            continue;
        }
    ?>
    <li>
        <a href="{{ download.url }}" target="_blank">
            {{ download.title }}
            <br>
            {{ download.filename }}
            <br>
            {{ download.size }}
        </a>
    </li>
<?ev } ?>
</ul>

Learn more about ProductDownload objects