How To

How to Use Tab Widget in Magento 2

Hello Magento Friends,

Today I am going to figure out How to Use Tab Widget in Magento 2.

Tabs are used to break content into various sections to save space. The user can switch between various tabs. Magento 2 provides many readymade widgets, using that widget you can create a standard theme very easily.

Let’s learn How to Use Tab Widget in Magento 2

Steps to Use Tab Widget in Magento 2:

Step 1: To do this, override list.phtml in 

app\design\frontend\Themes\Yourtheme\Magento_Catalog\templates\product\list.phtml

<div class="product info detailed">
    <div class="product data items" data-mage-init='{"tabs":{"openedState":"active"}}'>
        <div class="data item title"
             data-role="collapsible" id="tab-label-1">
            <a class="data switch"
               tabindex="-1"
               data-toggle="trigger"
               href="#temp-1"
               id="tab-label-1-title">
                <?php __("Tab 1"); ?>
            </a>
        </div>
        <div class="data item content"
             aria-labelledby="tab-label-1-title" id="temp-1" data-role="content">
            <?php __("Hello Tab 1 Text"); ?>
        </div>
        <div class="data item title"
             data-role="collapsible" id="tab-label-2">
            <a class="data switch"
               tabindex="-1"
               data-toggle="trigger"
               href="#temp-2"
               id="tab-label-2-title">
                <?php __("Hello Tab 2 Text"); ?>
            </a>
        </div>
        <div class="data item content"
             aria-labelledby="tab-label-2-title" id="temp-2" data-role="content">
            Hello 2  Text
        </div>
    </div>
</div>

Here I have created one theme and override list.phtml file in Magento_catalog extension. You can use the above code anywhere you want in the phtml file.

Here is the example where the two tabs appear. It will show only one segment of content at a time. Changing a new “tab” will cause others in the same group to disappear and the new one to display alone. I have selected tab 2 so it will display only tab-2 text

Conclusion:

This way you can Use Tab Widget in Magento 2. In case of any difficulty, mention it in the comment below and share the article with your friends.

Happy Coding!

Click to rate this post!
[Total: 6 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

12 hours ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

12 hours ago

Magento 2: How to Add Header and Footer in Checkout

Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…

1 day ago

Understanding Flexbox Layout in React Native

Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…

3 days ago

HYVÄ Themes Releases: 1.3.6 & 1.3.7 – What’s New

We're thrilled to announce the release of Hyvä Themes 1.3.6 and 1.3.7! These latest updates…

3 days ago

How Modern E-Commerce Platforms Leverage Docker & Kubernetes for Scalability

Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…

4 days ago