2021-08-25 11:33:29 +00:00
|
|
|
+++
|
|
|
|
description = "Synchronize selection of content in different tabbed views"
|
|
|
|
title = "Tabbed views"
|
|
|
|
+++
|
2021-03-16 17:21:57 +00:00
|
|
|
|
|
|
|
Choose which content to see across the page. Very handy for providing code
|
|
|
|
snippets for multiple languages or providing configuration in different formats.
|
|
|
|
|
|
|
|
## Code example
|
|
|
|
|
2021-08-23 22:25:15 +00:00
|
|
|
````go
|
|
|
|
{{</* tabs */>}}
|
|
|
|
{{%/* tab name="python" */%}}
|
|
|
|
```python
|
|
|
|
print("Hello World!")
|
|
|
|
```
|
|
|
|
{{%/* /tab */%}}
|
|
|
|
{{%/* tab name="R" */%}}
|
|
|
|
```R
|
|
|
|
> print("Hello World!")
|
|
|
|
```
|
|
|
|
{{%/* /tab */%}}
|
|
|
|
{{%/* tab name="Bash" */%}}
|
|
|
|
```Bash
|
|
|
|
echo "Hello World!"
|
|
|
|
```
|
|
|
|
{{%/* /tab */%}}
|
|
|
|
{{</* /tabs */>}}
|
|
|
|
````
|
2021-03-16 17:21:57 +00:00
|
|
|
|
|
|
|
Renders as:
|
|
|
|
|
|
|
|
{{< tabs >}}
|
|
|
|
{{% tab name="python" %}}
|
|
|
|
```python
|
|
|
|
print("Hello World!")
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{% tab name="R" %}}
|
|
|
|
```R
|
|
|
|
> print("Hello World!")
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{% tab name="Bash" %}}
|
|
|
|
```Bash
|
|
|
|
echo "Hello World!"
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{< /tabs >}}
|
|
|
|
|
|
|
|
Tab views with the same tabs that belong to the same group sychronize their selection:
|
|
|
|
|
|
|
|
{{< tabs >}}
|
|
|
|
{{% tab name="python" %}}
|
|
|
|
```python
|
|
|
|
print("Hello World!")
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{% tab name="R" %}}
|
|
|
|
```R
|
|
|
|
> print("Hello World!")
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{% tab name="Bash" %}}
|
|
|
|
```Bash
|
|
|
|
echo "Hello World!"
|
|
|
|
```
|
|
|
|
{{% /tab %}}
|
|
|
|
{{< /tabs >}}
|
|
|
|
|
|
|
|
## Config example
|
|
|
|
|
2021-08-23 22:25:15 +00: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 17:21:57 +00:00
|
|
|
|
|
|
|
Renders as:
|
|
|
|
|
|
|
|
{{< tabs groupId="config" >}}
|
|
|
|
{{% 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 >}}
|
|
|
|
|
|
|
|
{{% notice warning %}}
|
|
|
|
When using tab views with different content sets, make sure to use a common `groupId` for equal sets but distinct
|
2021-08-23 21:51:52 +00:00
|
|
|
`groupId` for different sets. The `groupId` defaults to `'default'`.
|
|
|
|
**Take this into account across the whole site!**
|
2021-03-16 17:21:57 +00:00
|
|
|
The tab selection is restored automatically based on the `groupId` and if it cannot find a tab item because it came
|
2021-08-23 22:25:15 +00:00
|
|
|
from the `'default'` group on a different page then all tabs will be empty at first.
|
2021-03-16 17:21:57 +00:00
|
|
|
{{% /notice %}}
|