As I said: The nested shortcodes will work … but It would be cool if someone would think about a higher level component / widget type … to make this more “package friendly”.
I also need this feature for the documentation of my project. Could you point me to an example how to create a code tab with nested shortcodes with hugo?
In my case I’m using bootstrap nav-tabs. That requires a certain HTML structure and IDs that wouldn’t work for the shortcode structure that’s easy to use.
What I did was dump the contents into the DOM and then use JavaScript to fix up the structure, and used some onclick handling to make the correct tab active.
I spent a lot of time to do it.
Hugo doesn’t support it, although Hugo provided an example, but it is about how to use json, yaml or toml via transform.Remarshal. It doesn’t suit me because I needed other languages.
So what do you need for implementation:
$(document).ready(function () {
$('.tab-content').find('.tab-pane').each(function (idx, item) {
var navTabs = $(this).closest('.code-tabs').find('.nav-tabs'),
title = $(this).attr('title');
navTabs.append('<li><a href="#">' + title + '</a></li');
});
updateCurrentTab()
$('.nav-tabs a').click(function (e) {
e.preventDefault();
var tab = $(this).parent(),
tabIndex = tab.index(),
tabPanel = $(this).closest('.code-tabs'),
tabPane = tabPanel.find('.tab-pane').eq(tabIndex);
tabPanel.find('.active').removeClass('active');
tab.addClass('active');
tabPane.addClass('active');
// Store the number of config language selected in users' localStorage
if(window.localStorage) {
window.localStorage.setItem("configLangPref", tabIndex + 1)
}
// After click update here not only selected part of code but others
updateCurrentTab()
});
function updateCurrentTab() {
var holder = '.nav-tabs a'
// By default current tab number is 1
var tabNumber = 1
// Get saved tab number
if (window.localStorage.getItem('configLangPref')) {
tabNumber = window.localStorage.getItem('configLangPref')
}
// Remove 'active' code to avoid multiple examples of code
$('.nav-tabs a').closest('.code-tabs').find('.active').removeClass('active');
// Set 'active' state to current li(language) and div(code) by tabNumber
$('.code-tabs ul.nav-tabs').find("li:nth-of-type(" + tabNumber + ")" ).addClass('active');
$('.code-tabs .tab-content').find("div:nth-of-type(" + tabNumber + ")").addClass('active');
}
});
I hope it will help you