|
| 1 | +--- |
| 2 | +rows: |
| 3 | + - component: tab |
| 4 | + - title: This tab does not exist |
| 5 | + active: true |
| 6 | + link: ?component=tab&tab=tab_1 |
| 7 | + - title: I am not a true tab |
| 8 | + link: ?component=tab&tab=tab_2 |
| 9 | + - title: Do not click here |
| 10 | + link: ?component=tab&tab=tab_3 |
| 11 | +--- |
| 12 | + |
| 13 | +This example shows a very basic set of three tabs. The first tab is active. You could use this at the top of a page for easy navigation. |
| 14 | + |
| 15 | +To implement contents that change based on the active tab, use the `tab` parameter in the page query string. |
| 16 | +For example, if the page is `/my-page.sql`, then the first tab will have a link of `/my-page.sql?tab=My+First+tab`. |
| 17 | + |
| 18 | +You could then for instance display contents coming from the database based on the value of the `tab` parameter. |
| 19 | +For instance: `SELECT 'text' AS component, contents_md FROM my_page_contents WHERE tab = $tab`. |
| 20 | +Or you could write different queries for different tabs and use the `$tab` parameter with a static value in a where clause to switch between tabs: |
| 21 | + |
| 22 | +```sql |
| 23 | +set tab = coalesce($tab, 'Projects'); |
| 24 | +select 'tab' as component; |
| 25 | +select 'Projects' as title, $tab = 'Projects' as active; |
| 26 | +select 'Tasks' as title, $tab = 'Tasks' as active; |
| 27 | + |
| 28 | +select 'table' as component; |
| 29 | + |
| 30 | +select * from my_projects where $tab = 'Projects'; |
| 31 | +select * from my_tasks where $tab = 'Tasks'; |
| 32 | +``` |
| 33 | + |
| 34 | +Note that the example below is completely static, and does not use the `tab` parameter to actually switch between tabs. |
| 35 | +The query above defaults to Projects on the first visit; the links then select either `?tab=Projects` or `?tab=Tasks`. |
0 commit comments