2021-08-25 11:33:29 +00:00
+++
2022-06-05 17:31:59 +00:00
description = "Show content in tabbed views"
2023-01-14 00:39:28 +00:00
title = "Tabs"
2021-08-25 11:33:29 +00:00
+++
2021-03-16 17:21:57 +00:00
2023-01-14 00:39:28 +00:00
The `tabs` shortcode displays arbitrary content in unlimited number of tabs.
This comes in handy eg. for providing code snippets for multiple languages or providing configuration in different formats.
2021-03-16 17:21:57 +00:00
2022-06-23 11:24:54 +00:00
{{< tabs groupid = "tabs-example-language" > }}
2021-03-16 17:21:57 +00:00
{{% tab name="python" %}}
2022-06-05 17:31:59 +00:00
2021-03-16 17:21:57 +00:00
```python
print("Hello World!")
```
2022-06-05 17:31:59 +00:00
2021-03-16 17:21:57 +00:00
{{% /tab %}}
2022-06-05 17:31:59 +00:00
{{% tab name="bash" %}}
```bash
2021-03-16 17:21:57 +00:00
echo "Hello World!"
```
2022-06-05 17:31:59 +00:00
2021-03-16 17:21:57 +00:00
{{% /tab %}}
{{< / tabs > }}
2022-06-05 17:31:59 +00:00
## Usage
2021-03-16 17:21:57 +00:00
2022-06-22 22:03:24 +00:00
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
2022-06-23 11:24:54 +00:00
{{< tabs groupid = "shortcode-parameter" > }}
2022-06-22 22:03:24 +00:00
{{% tab name="shortcode" %}}
2022-06-05 17:31:59 +00:00
````go
{{< /* tabs */>}}
{{%/* tab name="python" */%}}
2021-03-16 17:21:57 +00:00
```python
print("Hello World!")
```
2022-06-05 17:31:59 +00:00
{{%/* /tab */%}}
{{%/* tab name="bash" */%}}
```bash
2021-03-16 17:21:57 +00:00
echo "Hello World!"
```
2022-06-05 17:31:59 +00:00
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
2022-06-22 22:03:24 +00:00
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/tabs.html" (dict
"context" .
"tabs" (slice
(dict
"name" "python"
"content" ("```python\nprint(\"Hello World!\")\n```" | markdownify)
)
(dict
"name" "bash"
"content" ("```bash\necho \"Hello World!\"\n```" | markdownify)
)
)
)}}
````
{{% /tab %}}
{{< / tabs > }}
2022-06-05 17:31:59 +00:00
### Parameter
| Name | Default | Notes |
|:----------------------|:-----------------|:------------|
2022-10-02 22:24:37 +00:00
| **groupid** | `default` | Arbitrary name of the group the tab view belongs to.< br >< br > Tab views with the same **groupid** sychronize their selected tab. This sychronization applies to the whole site! |
2022-06-05 17:31:59 +00:00
| _**<content>**_ | _<empty>_ | Arbitrary number of tabs defined with the `tab` sub-shortcode. |
2022-06-22 20:16:22 +00:00
{{% notice note %}}
2022-06-23 11:24:54 +00:00
When using tab views with different content sets, make sure to use a common `groupid` for equal sets of tabs but distinct `groupid` for different sets.
2022-06-05 17:31:59 +00:00
2022-06-23 11:24:54 +00:00
The tab selection is restored automatically based on the `groupid` and if it cannot find a tab item because it came from the `'default'` group on a different page then the first tab is selected instead.
2022-06-05 17:31:59 +00:00
{{% /notice %}}
2021-03-16 17:21:57 +00:00
2022-06-05 17:31:59 +00:00
## Examples
2022-06-23 11:24:54 +00:00
### Distinct `groupid`
2021-03-16 17:21:57 +00:00
2021-08-23 22:25:15 +00:00
````go
2022-06-23 11:24:54 +00:00
{{< /* tabs groupid="config" */>}}
2021-08-23 22:25:15 +00:00
{{%/* tab name="json" */%}}
```json
{
"Hello": "World"
}
```
{{%/* /tab */%}}
{{%/* tab name="XML" */%}}
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
{{%/* tab name="properties" */%}}
```properties
Hello = World
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
2021-03-16 17:21:57 +00:00
2022-06-23 11:24:54 +00:00
{{< tabs groupid = "tabs-example-config" > }}
2021-03-16 17:21:57 +00:00
{{% tab name="json" %}}
```json
{
"Hello": "World"
}
```
{{% /tab %}}
{{% tab name="XML" %}}
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
{{% tab name="properties" %}}
2021-08-23 22:25:15 +00:00
```ini
2021-03-16 17:21:57 +00:00
Hello = World
```
{{% /tab %}}
{{< / tabs > }}
2022-06-23 11:24:54 +00:00
### Non-Distinct `groupid`
2022-06-05 17:31:59 +00:00
See what happens to this tab view if you select **properties** tab from the previous example.
````go
2022-06-23 11:24:54 +00:00
{{< /* tabs groupid="config" */>}}
2022-06-05 17:31:59 +00:00
{{%/* tab name="json" */%}}
```json
{
"Hello": "World"
}
```
{{%/* /tab */%}}
{{%/* tab name="XML" */%}}
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
2022-06-23 11:24:54 +00:00
{{< tabs groupid = "tabs-example-config" > }}
2022-06-05 17:31:59 +00:00
{{% tab name="json" %}}
```json
{
"Hello": "World"
}
```
{{% /tab %}}
{{% tab name="XML" %}}
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
{{< / tabs > }}
2022-11-17 21:57:18 +00:00
### Nested Tabs
In case you want to nest tabs, the parent tab that contains the subtabs needs to be declared with `{{</* tab */>}}` instead of `{{%/* tab */%}}` . Note, that in this case it is not possible to put markdown in the parent tab.
````go
{{< /* tabs groupid="main" */>}}
{{< /* tab name="Text" */>}}
Simple text is possible here...
{{< /* tabs groupid="tabs-example-language" */>}}
{{%/* tab name="python" */%}}
Python is **super** easy.
- most of the time.
- if you don't want to output unicode
{{%/* /tab */%}}
{{%/* tab name="bash" */%}}
Bash is for **hackers** .
{{%/* /tab */%}}
{{< /* /tabs */>}}
{{< /* /tab */>}}
{{< /* tab name="Code" */>}}
...but no markdown
{{< /* tabs groupid="tabs-example-language" */>}}
{{%/* tab name="python" */%}}
```python
print("Hello World!")
```
{{%/* /tab */%}}
{{%/* tab name="bash" */%}}
```bash
echo "Hello World!"
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
{{< /* /tab */>}}
{{< /* /tabs */>}}
````
{{< tabs groupid = "main" > }}
{{< tab name = "Text" > }}
Simple text is possible here...
{{< tabs groupid = "tabs-example-language" > }}
{{% tab name="python" %}}
Python is **super** easy.
- most of the time.
- if you don't want to output unicode
{{% /tab %}}
{{% tab name="bash" %}}
Bash is for **hackers** .
{{% /tab %}}
{{< / tabs > }}
{{< / tab > }}
{{< tab name = "Code" > }}
...but no markdown
{{< tabs groupid = "tabs-example-language" > }}
{{% tab name="python" %}}
```python
print("Hello World!")
```
{{% /tab %}}
{{% tab name="bash" %}}
```bash
echo "Hello World!"
```
{{% /tab %}}
{{< / tabs > }}
{{< / tab > }}
{{< / tabs > }}