Skip to content

Commit 0561724

Browse files
committed
run_sql documentation in shell component
1 parent 184440f commit 0561724

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,63 @@ You see the [page layouts demo](./examples/layouts.sql) for a live example of th
775775
"footer": "Official [SQLPage](https://sql.ophir.dev) documentation"
776776
}]')),
777777
('shell', '
778+
### Sharing the shell between multiple pages
779+
780+
It is common to want to share the same shell between multiple pages.
781+
782+
#### Static menu
783+
784+
If your menu is completely static (it does not depend on the database content),
785+
you can use the [`dynamic`](?component=dynamic#component) component together with the
786+
[`sqlpage.read_file_as_text`](functions.sql?function=read_file_as_text#function) function to load the shell from
787+
a json file.
788+
789+
```sql
790+
SELECT ''dynamic'' AS component, sqlpage.read_file_as_text(''shell.json'') AS properties;
791+
```
792+
793+
and in `shell.json`:
794+
795+
```json
796+
{
797+
"component": "shell",
798+
"title": "SQL + JSON = <3",
799+
"link": "/",
800+
"menu_item": [
801+
{"link": "index.sql", "title": "Home"},
802+
{"title": "Community", "submenu": [
803+
{"link": "blog.sql", "title": "Blog"},
804+
{"link": "//github.com/lovasoa/sqlpage", "title": "Github"}
805+
]}
806+
]
807+
}
808+
```
809+
810+
#### Dynamic menu
811+
812+
If your menu depends on the database content, or on special `sqlpage` functions,
813+
you can use the `dynamic` component,
814+
but this time with the [`sqlpage.run_sql`](functions.sql?function=run_sql#function)
815+
function to generate the menu from the database.
816+
817+
```sql
818+
SELECT ''dynamic'' AS component, sqlpage.run_sql(''shell.sql'') AS properties;
819+
```
820+
821+
and in `shell.sql`:
822+
823+
```sql
824+
SELECT ''shell'' AS component, ''run_sql is cool'' as title,
825+
json_group_array(json_object(
826+
''link'', link,
827+
''title'', title
828+
)) as menu_item
829+
FROM my_menu_items
830+
```
831+
832+
(check your database documentation for the exact syntax of the `json_group_array` function).
833+
', NULL),
834+
('shell', '
778835
### A page without a shell
779836
SQLPage provides the `shell-empty` component to create a page without a shell.
780837
In this case, the `html` and `body` tags are not generated, and the components are rendered directly in the page

0 commit comments

Comments
 (0)