2021-08-25 13:33:29 +02:00
+++
2022-06-05 19:31:59 +02:00
description = "Show content in tabbed views"
2021-08-25 13:33:29 +02:00
title = "Tabbed views"
+++
2021-03-16 18:21:57 +01:00
2022-06-05 19:31:59 +02: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 18:21:57 +01:00
2022-05-29 23:35:16 +02:00
{{< tabs groupId = "tabs-example-language" > }}
2021-03-16 18:21:57 +01:00
{{% tab name="python" %}}
2022-06-05 19:31:59 +02:00
2021-03-16 18:21:57 +01:00
```python
print("Hello World!")
```
2022-06-05 19:31:59 +02:00
2021-03-16 18:21:57 +01:00
{{% /tab %}}
2022-06-05 19:31:59 +02:00
{{% tab name="bash" %}}
```bash
2021-03-16 18:21:57 +01:00
echo "Hello World!"
```
2022-06-05 19:31:59 +02:00
2021-03-16 18:21:57 +01:00
{{% /tab %}}
{{< / tabs > }}
2022-06-05 19:31:59 +02:00
## Usage
2021-03-16 18:21:57 +01:00
2022-06-05 19:31:59 +02:00
````go
{{< /* tabs */>}}
{{%/* tab name="python" */%}}
2021-03-16 18:21:57 +01:00
```python
print("Hello World!")
```
2022-06-05 19:31:59 +02:00
{{%/* /tab */%}}
{{%/* tab name="bash" */%}}
```bash
2021-03-16 18:21:57 +01:00
echo "Hello World!"
```
2022-06-05 19:31:59 +02:00
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
### Parameter
| Name | Default | Notes |
|:----------------------|:-----------------|:------------|
| **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! |
| _**<content>**_ | _<empty>_ | Arbitrary number of tabs defined with the `tab` sub-shortcode. |
2022-06-22 22:16:22 +02:00
{{% notice note %}}
2022-06-05 19:31:59 +02: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-22 22:16:22 +02: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 19:31:59 +02:00
{{% /notice %}}
2021-03-16 18:21:57 +01:00
2022-06-05 19:31:59 +02:00
## Examples
### Distinct `groupId`
2021-03-16 18:21:57 +01:00
2021-08-24 00:25:15 +02:00
````go
{{< /* tabs groupId="config" */>}}
{{%/* 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 18:21:57 +01:00
2022-05-29 23:35:16 +02:00
{{< tabs groupId = "tabs-example-config" > }}
2021-03-16 18:21:57 +01:00
{{% tab name="json" %}}
```json
{
"Hello": "World"
}
```
{{% /tab %}}
{{% tab name="XML" %}}
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
{{% tab name="properties" %}}
2021-08-24 00:25:15 +02:00
```ini
2021-03-16 18:21:57 +01:00
Hello = World
```
{{% /tab %}}
{{< / tabs > }}
2022-06-05 19:31:59 +02:00
### Non-Distinct `groupId`
See what happens to this tab view if you select **properties** tab from the previous example.
````go
{{< /* tabs groupId="config" */>}}
{{%/* tab name="json" */%}}
```json
{
"Hello": "World"
}
```
{{%/* /tab */%}}
{{%/* tab name="XML" */%}}
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
{{< tabs groupId = "tabs-example-config" > }}
{{% tab name="json" %}}
```json
{
"Hello": "World"
}
```
{{% /tab %}}
{{% tab name="XML" %}}
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
{{< / tabs > }}