Recent searches


No recent searches

Add Tab functionality in the Copenhagen theme



image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

Posted Jun 18, 2024

Hi Community,

 

This tip is for adding the Tab fetaure to your Guide theme for article page, category, section pages.

 

Credit: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_tabs

 

Please follow the steps below:

 

i). Go to your hbs file where your want to add tabs.

ii). Add the given code to that hbs file.

 

<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')">London</button>
  <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>

<div id="London" class="tabcontent">
  <h3>London</h3>
  <p>London is the capital city of England.</p>
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p> 
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>

 

 

If you want add Tab to the article page, you must add this in the 'Source code' while creating the article. Please see the given sreenshot.

 

iii). In the given HTML code, there are demo text, remove that and add yours.

iv). After that, open style.css file and add the given CSS code.

 

/* Style the tab */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
  background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
  background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
}

v). Open your script.js file and add the given code.

 

function openCity(evt, cityName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}

 

Also, please check the security settings,

 

Guide > Setting > Guide Setting > Security > Check the checkbox 'Display Unsafe content' > Save

 

 

Output is :

 

If you face any issues feel free to ask :)

Thank You


2

0

0 comments

Please sign in to leave a comment.

Didn't find what you're looking for?

New post