I have an attribute "brand" with type Swatch.

I have created many brands as an option in this attribute.

I want to filter brands label which are starts with a particular letter (ex. A or B or C).

1 Answer 1


Well, I am using manufacturer as a brand so in my case.

Make Magento_catalog->templates->product->view->brand_info.phtml and put that code.

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();

$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

if ($_attributeLabel && $_attributeLabel == 'default') {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();

$_attributeValue =$_product->getResource()->getAttribute($_code)->getFrontend()->getValue($_product);
<?php if ($_attributeValue): ?>
<div class="product_<?php echo $_className?>"><?php if ($_attributeLabel != 'none'): ?><h4 class="brand" itemscope itemtype="http://schema.org/Brand">Brand:&nbsp;</h4><?php endif; ?><div class="brand-value" itemprop="brand"<?php echo $_attributeAddAttribute;?>><h4>&nbsp;<?php echo $_attributeValue; ?></h4></div>
<?php endif; ?>



then make a layout in Magento_catalog->layout->catalog_product_view.xml put that code according to your attribute name.

<?xml version="1.0"?>

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="product.info.price">
        <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.brand" template="product/view/brand_info.phtml" before="-">
        <argument name="at_call" xsi:type="string">getBrand</argument>
        <argument name="at_code" xsi:type="string">manufacturer2</argument>
        <argument name="css_class" xsi:type="string">brand</argument>
        <argument name="at_label" xsi:type="string">default</argument>
        <argument name="add_attribute" xsi:type="string">itemprop="manufacturer2"</argument>

  • I am not asking for products. I have separate page In which all the brands (attribute) are display but suppose customer wants to see brands which name is starts from A then he needs to click on letter (A-Z) and I will display all the brand list which are starts from A letter.
    – user88667
    Apr 23, 2020 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.