Magento print page layout

Magento print page layout

July 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento print page layout

Customizing Magento Print Page Layout: A Developer’s Guide

In e-commerce development, providing convenient printing options for customers is crucial. This guide will walk you through the process of creating a custom print page layout in Magento, similar to the pop-up style you’ve seen on another site.

Understanding Magento Print Functionality

Before we dive into the customization process, let’s briefly discuss how printing works in Magento. By default, when you click the “Print” button on a product view page in Magento 2, it opens a new tab with the page content. However, this doesn’t provide the specific layout or style you’re looking for.

Setting Up Your Print Page Layout

To achieve the desired pop-up effect with custom print page attributes, you’ll need to create a new template and override the default Magento functionality.

Step 1: Create a Custom Template

Navigate to your theme directory (usually found in app/design/frontend/[Vendor]/[Theme]). If you don’t have a specific theme folder yet, create one following the standard Magento theme structure.

Inside this theme folder, look for or create a new folder named Magento_Theme if it doesn’t exist. Within this folder, create another folder called templates. This is where we’ll store our custom template file.

Step 2: Override the Print Function

Create a new PHP file in the templates folder you created earlier. Name this file print.phtml. This will be the main template for your print pop-up page.

Step 3: Customize Your Template

Open the print.phtml file and begin adding your custom HTML structure. You can keep the basic CSS styling intact, but feel free to add or remove elements as needed to match the design of your choice.

For example, you might want to include sections for product name, images, description, brand, price, and any other relevant attributes:

<div class="print-popup">
    <h1 class="product-name"><?= $block->escapeHtml($product->getName()) ?></h1>
    <div class="product-images">
        <?= $block->getImage($_product, 'category_page_list') ?>
    </div>
    <div class="product-description">
        <?= $block->getProductAttributeText('description'); ?>
    </div>
    <p>Brand: <?= $block->escapeHtml($product->getAttributeText('brand')); ?></p>
    <p>Price: <?= $block->escapeHtml($product->getFinalPrice()); ?></p>
</div>

Integrating Your Custom Print Function

To make your print pop-up functional, you’ll need to modify the default Magento print button behavior.

Step 4: Create a New JavaScript File

In your theme directory (in app/design/frontend/[Vendor]/[Theme]), navigate to the web/js folder. If it doesn’t exist, create it following the standard Magento structure.

Inside this folder, create a new file called custom-print.js. This will contain the custom JavaScript logic for your print pop-up window.

Step 5: Implement Your Print Logic

In the custom-print.js file, add the necessary JavaScript code to handle the print button click event and open your custom template in a pop-up:

require(['jquery'], function ($) {
    $(document).ready(function () {
        $('#print-button').on('click', function (e) {
            e.preventDefault();
            var popup = window.open('', 'print-popup-window', 'width=600,height=600,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no');
            popup.document.write('<html><head><title>Product Print</title></head><body>');
            popup.document.write($('div.print-popup').html());
            popup.document.write('</body></html>');
        });
    });
});

Step 6: Enqueue Your JavaScript File

To ensure your custom JavaScript file is loaded, you need to enqueue it in the appropriate Magento layout.

Back in your theme directory (app/design/frontend/[Vendor]/[Theme]), navigate to the Magento_Theme folder and open or create the requirejs-config.js file. Add the following line inside the config object:

map: {
    '*': {
        'custom-print': 'Magento_Company/js/custom-print'
    }
},

Step 7: Update Your Product View Layout

Finally, update your product view layout to include your custom JavaScript file and set up the print button.

In your theme directory (app/design/frontend/[Vendor]/[Theme]), navigate to the Magento_Catalog folder and open or create the catalog_product_view.xml file. Add the following XML nodes inside the <referenceContainer name="content"> section:

<referenceBlock name="product.info">
    <block class="Magento\Catalog\Block\Product\View" template="Magento_Theme::print.phtml" ttl="86400">
        <arguments>
            <argument name="css_class" xsi:type="string">print-popup</argument>
        </arguments>
    </block>
</referenceBlock>

<referenceContainer name="head.components">
    <item name="custom-print" componentType="jsComponent">
        <component type="Magento_Company/js/custom-print"/>
    </item>
</referenceContainer>

Conclusion

By following this guide, you should now be able to create a custom print page layout in Magento that matches the desired pop-up style. This approach allows for greater control over the information displayed on the print page and provides a more user-friendly experience for your customers.

Remember, regular testing of your layouts is essential to ensure they function correctly across different devices and browsers. Always keep an eye on Magento’s official documentation for any updates or changes that might affect your customizations.

For further assistance with Magento development and customization, feel free to explore the resources available at LaravelCompany. We offer a wide range of services to help you optimize your e-commerce platforms.

Magento 2 Catalog Themes Configuration

Our network