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-05-23 21:57:48 +00:00
The `tabs` shortcode displays arbitrary content in an unlimited number of tabs.
2023-01-14 00:39:28 +00:00
2023-05-23 21:57:48 +00:00
This comes in handy eg. for providing code snippets for multiple languages.
2021-03-16 17:21:57 +00:00
2023-05-23 22:13:40 +00:00
If you just want a single tab you can instead call the [`tab` shortcode ]({{% relref "shortcodes/tab" %}} ) standalone.
2023-05-23 21:57:48 +00:00
2023-06-06 17:54:12 +00:00
{{< tabs title = "hello." > }}
{{% tab title="py" %}}
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 %}}
2023-06-06 17:54:12 +00:00
{{% tab title="sh" %}}
2022-06-05 17:31:59 +00:00
```bash
2021-03-16 17:21:57 +00:00
echo "Hello World!"
```
2022-06-05 17:31:59 +00:00
2023-06-06 17:54:12 +00:00
{{% /tab %}}
{{% tab title="c" %}}
```c
printf("Hello World!");
```
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.
2023-05-23 22:13:40 +00:00
See the [`tab` shortcode ]({{% relref "shortcodes/tab" %}} ) for a description of the parameter for nested tabs.
2022-06-23 11:24:54 +00:00
{{< tabs groupid = "shortcode-parameter" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="shortcode" %}}
2022-06-22 22:03:24 +00:00
2022-06-05 17:31:59 +00:00
````go
2023-06-06 17:54:12 +00:00
{{< /* tabs title="hello." */>}}
{{%/* tab title="py" */%}}
2021-03-16 17:21:57 +00:00
```python
print("Hello World!")
```
2022-06-05 17:31:59 +00:00
{{%/* /tab */%}}
2023-06-06 17:54:12 +00:00
{{%/* tab title="sh" */%}}
2022-06-05 17:31:59 +00:00
```bash
2021-03-16 17:21:57 +00:00
echo "Hello World!"
```
2022-06-05 17:31:59 +00:00
{{%/* /tab */%}}
2023-06-06 17:54:12 +00:00
{{%/* tab title="c" */%}}
```c
printf"Hello World!");
```
{{%/* /tab */%}}
2022-06-05 17:31:59 +00:00
{{< /* /tabs */>}}
````
2022-06-22 22:03:24 +00:00
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="partial" %}}
2022-06-22 22:03:24 +00:00
````go
{{ partial "shortcodes/tabs.html" (dict
"context" .
2023-06-06 17:54:12 +00:00
"title" "hello."
2023-05-23 21:57:48 +00:00
"content" (slice
2022-06-22 22:03:24 +00:00
(dict
2023-06-06 17:54:12 +00:00
"title" "py"
2023-06-03 11:14:15 +00:00
"content" ("```python\nprint(\"Hello World!\")\n```" | .RenderString)
2022-06-22 22:03:24 +00:00
)
(dict
2023-06-06 17:54:12 +00:00
"title" "sh"
2023-06-03 11:14:15 +00:00
"content" ("```bash\necho \"Hello World!\"\n```" | .RenderString)
2022-06-22 22:03:24 +00:00
)
2023-06-06 17:54:12 +00:00
(dict
"title" "c"
"content" ("```c\nprintf(\"Hello World!\");\n```" | .RenderString)
)
2022-06-22 22:03:24 +00:00
)
)}}
````
{{% /tab %}}
{{< / tabs > }}
2022-06-05 17:31:59 +00:00
### Parameter
2023-05-23 21:57:48 +00:00
| Name | Default | Notes |
|:----------------------|:---------------------|:------------|
| **groupid** | _<random>_ | Arbitrary name of the group the tab view belongs to.< br >< br > Tab views with the same **groupid** sychronize their selected tab. The tab selection is restored automatically based on the `groupid` for tab view. If the selected tab can not be found in a tab group the first tab is selected instead.< br >< br > This sychronization applies to the whole site! |
2023-06-05 22:31:57 +00:00
| **style** | _<empty>_ | Sets a default value for every contained tab. Can be overridden by each tab. See the [`tab` shortcode ]({{% relref "shortcodes/tab#parameter" %}} ) for possible values. |
| **color** | _<empty>_ | Sets a default value for every contained tab. Can be overridden by each tab. See the [`tab` shortcode ]({{% relref "shortcodes/tab#parameter" %}} ) for possible values. |
2023-06-07 22:10:37 +00:00
| **title** | _<empty>_ | Arbitrary title written in front of the tab view. |
2023-06-06 17:54:12 +00:00
| **icon** | _<empty>_ | [Font Awesome icon name ]({{%relref "shortcodes/icon#finding-an-icon" %}} ) set to the left of the title. |
2023-05-23 21:57:48 +00:00
| _**<content>**_ | _<empty>_ | Arbitrary number of tabs defined with the `tab` sub-shortcode. |
2022-06-05 17:31:59 +00:00
2023-05-23 21:57:48 +00:00
## Examples
2022-06-05 17:31:59 +00:00
2023-05-23 21:57:48 +00:00
### Behavior of the `groupid`
2021-03-16 17:21:57 +00:00
2023-05-23 21:57:48 +00:00
See what happens to the tab views while you select different tabs.
2022-06-05 17:31:59 +00:00
2023-06-07 22:10:37 +00:00
While pressing a tab of Group A switches all tab views of Group A in sync (if the tab is available), the tabs of Group B are left untouched.
2021-03-16 17:21:57 +00:00
2023-05-23 21:57:48 +00:00
{{< tabs > }}
2023-06-05 21:20:37 +00:00
{{% tab title="Group A, Tab View 1" %}}
2021-08-23 22:25:15 +00:00
````go
2023-05-23 21:57:48 +00:00
{{< /* tabs groupid="a" */>}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="json" */%}}
2021-08-23 22:25:15 +00:00
```json
2023-05-23 21:57:48 +00:00
{ "Hello": "World" }
2021-08-23 22:25:15 +00:00
```
{{%/* /tab */%}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="_**XML**_ stuff" */%}}
2021-08-23 22:25:15 +00:00
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
2023-06-07 18:16:59 +00:00
{{%/* tab title="text" */%}}
Hello World
2021-08-23 22:25:15 +00:00
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
2023-05-23 21:57:48 +00:00
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="Group A, Tab View 2" %}}
2023-05-23 21:57:48 +00:00
````go
{{< /* tabs groupid="a" */>}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="json" */%}}
2023-05-23 21:57:48 +00:00
```json
{ "Hello": "World" }
```
{{%/* /tab */%}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="XML stuff" */%}}
2023-05-23 21:57:48 +00:00
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="Group B" %}}
2023-05-23 21:57:48 +00:00
````go
{{< /* tabs groupid="b" */>}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="json" */%}}
2023-05-23 21:57:48 +00:00
```json
{ "Hello": "World" }
```
{{%/* /tab */%}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="XML stuff" */%}}
2023-05-23 21:57:48 +00:00
```xml
< Hello > World< / Hello >
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
````
{{% /tab %}}
{{< / tabs > }}
#### Group A, Tab View 1
2021-03-16 17:21:57 +00:00
2023-05-23 21:57:48 +00:00
{{< tabs groupid = "tab-example-a" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="json" %}}
2021-03-16 17:21:57 +00:00
```json
2023-05-23 21:57:48 +00:00
{ "Hello": "World" }
2021-03-16 17:21:57 +00:00
```
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="_**XML**_ stuff" %}}
2021-03-16 17:21:57 +00:00
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
2023-06-07 18:16:59 +00:00
{{% tab title="text" %}}
Hello World
2021-03-16 17:21:57 +00:00
{{% /tab %}}
{{< / tabs > }}
2023-05-23 21:57:48 +00:00
#### Group A, Tab View 2
2022-06-05 17:31:59 +00:00
2023-05-23 21:57:48 +00:00
{{< tabs groupid = "tab-example-a" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="json" %}}
2022-06-05 17:31:59 +00:00
```json
2023-05-23 21:57:48 +00:00
{ "Hello": "World" }
2022-06-05 17:31:59 +00:00
```
2023-05-23 21:57:48 +00:00
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="XML stuff" %}}
2022-06-05 17:31:59 +00:00
```xml
< Hello > World< / Hello >
```
2023-05-23 21:57:48 +00:00
{{% /tab %}}
{{< / tabs > }}
#### Group B
2022-06-05 17:31:59 +00:00
2023-05-23 21:57:48 +00:00
{{< tabs groupid = "tab-example-b" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="json" %}}
2022-06-05 17:31:59 +00:00
```json
2023-05-23 21:57:48 +00:00
{ "Hello": "World" }
2022-06-05 17:31:59 +00:00
```
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="XML stuff" %}}
2022-06-05 17:31:59 +00:00
```xml
< Hello > World< / Hello >
```
{{% /tab %}}
{{< / tabs > }}
2022-11-17 21:57:18 +00:00
2023-06-07 22:10:37 +00:00
### Nested Tab Views and Color
2022-11-17 21:57:18 +00:00
2023-06-07 22:10:37 +00:00
In case you want to nest tab views, the parent tab that contains nested tab views 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.
2022-11-17 21:57:18 +00:00
2023-06-07 22:10:37 +00:00
You can also set style and color parameter for all tabs and overwrite them on tab level. See the [`tab` shortcode ]({{% relref "shortcodes/tab#parameter" %}} ) for possible values.
2023-06-05 22:31:57 +00:00
2022-11-17 21:57:18 +00:00
````go
2023-06-06 17:54:12 +00:00
{{< /* tabs groupid="main" style="primary" title="Rationale" icon="thumbtack" */>}}
2023-06-05 21:20:37 +00:00
{{< /* tab title="Text" */>}}
2022-11-17 21:57:18 +00:00
Simple text is possible here...
{{< /* tabs groupid="tabs-example-language" */>}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="python" */%}}
2022-11-17 21:57:18 +00:00
Python is **super** easy.
- most of the time.
- if you don't want to output unicode
{{%/* /tab */%}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="bash" */%}}
2022-11-17 21:57:18 +00:00
Bash is for **hackers** .
{{%/* /tab */%}}
{{< /* /tabs */>}}
{{< /* /tab */>}}
2023-06-06 17:54:12 +00:00
{{< /* tab title="Code" style="default" color="darkorchid" */>}}
2022-11-17 21:57:18 +00:00
...but no markdown
{{< /* tabs groupid="tabs-example-language" */>}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="python" */%}}
2022-11-17 21:57:18 +00:00
```python
print("Hello World!")
```
{{%/* /tab */%}}
2023-06-05 21:20:37 +00:00
{{%/* tab title="bash" */%}}
2022-11-17 21:57:18 +00:00
```bash
echo "Hello World!"
```
{{%/* /tab */%}}
{{< /* /tabs */>}}
{{< /* /tab */>}}
{{< /* /tabs */>}}
````
2023-06-06 17:54:12 +00:00
{{< tabs groupid = "main" style = "primary" title = "Rationale" icon = "thumbtack" > }}
2023-06-05 21:20:37 +00:00
{{< tab title = "Text" > }}
2022-11-17 21:57:18 +00:00
Simple text is possible here...
{{< tabs groupid = "tabs-example-language" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="python" %}}
2022-11-17 21:57:18 +00:00
Python is **super** easy.
- most of the time.
- if you don't want to output unicode
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="bash" %}}
2022-11-17 21:57:18 +00:00
Bash is for **hackers** .
{{% /tab %}}
{{< / tabs > }}
{{< / tab > }}
2023-06-06 17:54:12 +00:00
{{< tab title = "Code" style = "default" color = "darkorchid" > }}
2022-11-17 21:57:18 +00:00
...but no markdown
{{< tabs groupid = "tabs-example-language" > }}
2023-06-05 21:20:37 +00:00
{{% tab title="python" %}}
2022-11-17 21:57:18 +00:00
```python
print("Hello World!")
```
{{% /tab %}}
2023-06-05 21:20:37 +00:00
{{% tab title="bash" %}}
2022-11-17 21:57:18 +00:00
```bash
echo "Hello World!"
```
{{% /tab %}}
{{< / tabs > }}
{{< / tab > }}
{{< / tabs > }}