Skip to main content

Use a custom block template

You can add your own template for a product block in your theme. Use it to change the product card: show product attributes or specifications, hide or resize the image, or change the layout.

The template is part of your theme, so module upgrades do not overwrite it.

Add the template​

  1. Copy one of the module templates as a starting point: vendor/mirasvit/module-related/src/Related/view/frontend/templates/block/default.phtml The same folder also contains bulletproof.phtml and widget.phtml.
  2. Put the copy into your theme with a new name: app/design/frontend/<Vendor>/<theme>/Mirasvit_Related/templates/block/<name>.phtml
  3. Change the template. For example, to show an attribute value in the product card, use $product->getAttributeText('color') for a dropdown attribute, or $product->getData('material') for a text attribute. Make sure the attribute is available in the product listing: set Used in Product Listing to Yes for the attribute.
  4. Go to Marketing > Related products > Product blocks, open the block and select your template in How to display > Template. The template name is the file name with a capital first letter, for example attributes.phtml shows as Attributes.
  5. Flush the Magento cache.
note
  • The Template list shows templates from all themes in app/design/frontend. Put the template into the theme that the store uses, or into its parent theme. Otherwise the block is not displayed.
  • Themes installed with Composer (in the vendor folder) are not scanned. Put your template into a theme in app/design/frontend.
  • The template applies to blocks with a regular position. Blocks with the positions Add into Native Related Block, Add into Native Upsell Block and Add into Native Cross Sell Block use the template of the native Magento block.

Hyvä themes​

Use the same theme path: app/design/frontend/<Vendor>/<theme>/Mirasvit_Related/templates/block/<name>.phtml.

The module templates contain a separate branch for Hyvä, inside if (isset($hyvaCsp)). By default this branch renders the products with the product card of your Hyvä theme (Magento_Catalog::product/list/item.phtml). To change the card only for this block, replace the code in this branch with your own markup.

After you add Tailwind CSS classes to the template, rebuild the styles of your theme.