Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions examples/official-site/content/components/shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
icon: layout-navbar
category: page-layout
summary: Set the page layout, navigation, branding, and footer.
top:
- name: class
type: TEXT
description: class attribute added to the page's html element. It can be used to apply custom styling to
the whole page through css.
- name: css
type: URL
description: The URL of a CSS file to load and apply to the page.
- name: description
type: TEXT
description: A description of the page. It can be displayed by search engines when your page appears in
their results.
- name: favicon
type: URL
description: The URL of the icon the web browser should display in bookmarks and tabs. This property is
particularly useful if multiple sites are hosted on the same domain with different [``site_prefix``](https://github.com/sqlpage/SQLPage/blob/main/configuration.md#configuring-sqlpage).
- name: fixed_top_menu
type: BOOLEAN
description: Fixes the top bar with menu at the top (the top bar remains visible when scrolling long pages).
- name: font
type: TEXT
description: Specifies the font to be used for displaying text, which can be a valid font name from fonts.google.com
or the path to a local WOFF2 font file starting with a slash (e.g., "/fonts/MyLocalFont.woff2").
- name: font_size
type: INTEGER
description: Font size on the page, in pixels. Set to 18 by default.
- name: footer
type: TEXT
description: Muted text to display in the footer of the page. This can be used to display a link to the
terms and conditions of your application, for instance. By default, shows "Built with SQLPage". Supports
links with markdown.
- name: icon
type: ICON
description: Name of an icon (from tabler-icons.io) to display next to the title in the navigation bar.
- name: image
type: URL
description: The URL of an image to display next to the page title.
- name: javascript
type: URL
description: The URL of a Javascript file to load and execute on the page.
- name: javascript_module
type: URL
description: The URL of a javascript module in the ESM format (see javascript.info/modules)
- name: language
type: TEXT
description: The language of the page. This can be used by search engines and screen readers to determine
in which language the page is written.
- name: layout
type: TEXT
description: The general page layout. Can be "boxed" (the default), "horizontal" (for a full-width menu),
"vertical"(vertical menu), "fluid" (removes side margins).
- name: link
type: URL
description: The target of the link in the top navigation bar.
- name: manifest
type: URL
description: The location of the [manifest.json](https://developer.mozilla.org/en-US/docs/Web/Manifest)
if the site is a [PWA](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps). Among other
features, serving a manifest enables your site to be "installed" as an app on most mobile devices.
- name: menu_item
type: TEXT
description: Adds a menu item in the navigation bar at the top of the page. The menu item will have the
specified name, and will link to as .sql file of the same name. A dropdown can be generated by passing
a json object with a `title` and `submenu` properties.
- name: navbar_title
type: TEXT
description: The title shown in the navigation bar or sidebar. Defaults to the page title. Set an empty
string to show just the logo.
- name: navbar_toggle_label
type: TEXT
description: Customizes the accessible name of the button that opens and closes the navigation menu on small
screens, which screen readers announce. Replaces the default "Toggle navigation".
- name: norobot
type: BOOLEAN
description: Forbids robots to save this page in their database and follow the links on this page. This
will prevent this page to appear in Google search results for any query, for instance.
- name: preview_image
type: URL
description: The URL of an image to display as a link preview when the page is shared on social media
- name: refresh
type: INTEGER
description: Number of seconds after which the page should refresh. This can be useful to display dynamic
content that updates automatically.
- name: rss
type: URL
description: The URL of an RSS feed to display in the top navigation bar. You can use the rss component
to generate the field.
- name: rtl
type: BOOLEAN
description: Whether the page should be displayed in right-to-left mode. Used to display Arabic, Hebrew,
Persian, etc.
- name: search_button
type: TEXT
description: Customizes the text displayed on the search button. Replaces the default "Search" label with
custom text that may better match your applications terminology or language.
- name: search_placeholder
type: TEXT
description: Customizes the placeholder text shown in the search input field. Replaces the default "Search"
with text that better describes what users should search for. It is also used as the accessible name
of the search field, which screen readers announce.
- name: search_target
type: TEXT
description: When this is set, a search field will appear in the top navigation bar, and load the specified
sql file with an URL parameter named "search" when the user searches something.
- name: search_value
type: TEXT
description: This value will be placed in the search field when "search_target" is set. Using the "$search"
query parameter value will mirror the value that the user has searched for.
- name: sidebar
type: BOOLEAN
description: Whether the menu defined by menu_item should be displayed on the left side of the page instead
of the top. Introduced in v0.27.
- name: sidebar_theme
type: TEXT
description: Used with sidebar property, It can be set to "dark" to exclusively set the sidebar into dark
theme.
- name: social_image
type: URL
description: The URL of the preview image that will appear in the Open Graph metadata when the page is
shared on social media.
- name: target
type: TEXT
description: 'Where the menu items should open: "_blank" for a new tab, "_self" for the same tab, "_parent"
for the parent frame, or "_top" for the full body of the window. Set it inside a "menu_item" json object;
it has no effect when set directly on the shell.'
- name: theme
type: TEXT
description: Set to "dark" to use a dark theme.
- name: title
type: TEXT
description: The title of your page. Will be shown in a top bar above the page contents. Also usually displayed
by web browsers as the name of the web page's tab.
---

Customize the overall layout, header and footer of the page.

This is a special component that provides the page structure wrapping all other components on your page.

It generates the complete HTML document including the `<head>` section with metadata, title, and stylesheets,
as well as the navigation bar, main content area, and footer.

If you don't explicitly call the shell component at the top of your SQL file, SQLPage will automatically
add a default shell component before your first try to display data on the page.

Use the shell component to customize page-wide settings like the page title, navigation menu, theme, fonts,
and to include custom visual styles (with CSS) or interactive behavior (with JavaScript) that should be loaded on the page.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
rows:
- component: shell
title: 'SQLPage: SQL websites'
navbar_title: SQLPage
link: /
menu_item:
- title: About
submenu:
- link: /safety.sql
title: Security
icon: lock
- link: /performance.sql
title: Performance
icon: bolt
- link: //github.com/sqlpage/SQLPage/blob/main/LICENSE.txt
title: License
icon: file-text
- link: /blog.sql
title: Articles
icon: book
- title: Examples
submenu:
- link: /examples/tabs/
title: Tabs
icon: layout-navbar
- link: /examples/layouts.sql
title: Layouts
icon: layout
- link: /examples/multistep-form
title: Forms
icon: edit
- link: /examples/handle_picture_upload.sql
title: File uploads
icon: upload
- link: /examples/authentication/
title: Password protection
icon: password-user
- link: //github.com/sqlpage/SQLPage/blob/main/examples/
title: All examples & demos
icon: code
- title: Community
submenu:
- link: /blog.sql
title: Blog
icon: book
- link: //github.com/sqlpage/SQLPage/issues
title: Report a bug
icon: bug
- link: //github.com/sqlpage/SQLPage/discussions
title: Discussions
icon: message
- link: //github.com/sqlpage/SQLPage
title: Github
icon: brand-github
- title: Documentation
submenu:
- link: /your-first-sql-website
title: Getting started
icon: book
- link: /components.sql
title: All Components
icon: list-details
- link: /functions.sql
title: SQLPage Functions
icon: math-function
- link: /extensions-to-sql
title: Extensions to SQL
icon: cube-plus
- link: /custom_components.sql
title: Custom Components
icon: puzzle
- link: //github.com/sqlpage/SQLPage/blob/main/configuration.md#configuring-sqlpage
title: Configuration
icon: settings
- title: Search
link: /search
layout: boxed
language: en-US
description: Go from SQL queries to web applications in an instant.
preview_image: https://sql-page.com/sqlpage_social_preview.webp
theme: dark
font_size: 19
image: /assets/icon.webp
favicon: /favicon.ico
javascript_module: /assets/highlightjs-launch.js
css: /assets/highlightjs-and-tabler-theme.css
footer: '[Built with SQLPage](https://github.com/sqlpage/SQLPage/tree/main/examples/official-site)'
---

This example configures a dark shell with menus linking to pages on this site.

Each `menu_item` object defines a link or a dropdown. The "Community" menu links to the blog, issue tracker, discussions, and source code.

The object form can be used directly only on database engines that have a native JSON type.
On other engines (such as SQLite), you can use the [`dynamic`](?component=dynamic#component) component to generate the same result.


You see the [page layouts demo](./examples/layouts.sql) for a live example of the different layouts.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
rows:
- component: shell
title: 'SQLPage: SQL websites'
icon: database
link: /
menu_item:
- title: Home
active: true
- title: About
---

This example shows how to set menu items as active in the navigation, so that they are highlighted in the nav bar.

In this example you can see that two menu items are created, "Home" and "About" and the "Home" tab is marked as active.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
### Sharing the shell between multiple pages

It is common to want to share the same shell between multiple pages.

#### Static menu

If your menu is completely static (it does not depend on the database content),
you can use the [`dynamic`](?component=dynamic#component) component together with the
[`sqlpage.read_file_as_text`](functions.sql?function=read_file_as_text#function) function to load the shell from
a json file.

```sql
SELECT 'dynamic' AS component, sqlpage.read_file_as_text('shell.json') AS properties;
```

and in `shell.json`:

```json
{
"component": "shell",
"title": "SQL + JSON = <3",
"link": "/",
"menu_item": [
{"link": "index.sql", "title": "Home"},
{"title": "Community", "submenu": [
{"link": "/blog.sql", "title": "Blog"},
{"link": "//github.com/sqlpage/SQLPage", "title": "Github"}
]}
]
}
```

#### Dynamic menu

If your menu depends on the database content, or on special `sqlpage` functions,
you can use the `dynamic` component,
but this time with the [`sqlpage.run_sql`](functions.sql?function=run_sql#function)
function to generate the menu from the database.

```sql
SELECT 'dynamic' AS component, sqlpage.run_sql('shell.sql') AS properties;
```

and in `shell.sql`:

```sql
SELECT 'shell' AS component, 'run_sql is cool' as title,
json_group_array(json_object(
'link', link,
'title', title
)) as menu_item
FROM my_menu_items
```

(check your database documentation for the exact syntax of the `json_group_array` function).

Another case when dynamic menus are useful is when you want to show some
menu items only in certain conditions.

For instance, you could show an "Admin panel" menu item only to users with the "admin" role,
a "Profile" menu item only to authenticated users,
and a "Login" menu item only to unauthenticated users:

```sql
set role = (
SELECT role FROM users
INNER JOIN sessions ON users.id = sessions.user_id
WHERE sessions.session_id = sqlpage.cookie('session_id')
); -- Read more about how to handle user sessions in the "authentication" component documentation

SELECT
'shell' AS component,
'My authenticated website' AS title,

-- Add an admin panel link if the user is an admin
CASE WHEN $role = 'admin' THEN '{"link": "admin.sql", "title": "Admin panel"}' END AS menu_item,

-- Add a profile page if the user is authenticated
CASE WHEN $role IS NOT NULL THEN '{"link": "profile.sql", "title": "My profile"}' END AS menu_item,

-- Add a login link if the user is not authenticated
CASE WHEN $role IS NULL THEN 'login' END AS menu_item
;
```

More about how to handle user sessions in the [authentication component documentation](?component=authentication#component).

### Menu with icons

The "icon" attribute may be specified for items in the top menu and submenus to display an icon
before the title (or instead). Similarly, the "image" attribute defines a file-based icon. For
image-based icons, the "size" attribute may be specified at the top level of menu_item only to
reduce the size of image-based icons. The following snippet provides an example, which is also
available [here](examples/menu_icon.sql).

```sql
SELECT
'shell' AS component,
'SQLPage' AS title,
'database' AS icon,
'/' AS link,
TRUE AS fixed_top_menu,
'{"title":"About","icon": "settings","submenu":[{"link":"/safety.sql","title":"Security","icon": "logout"},{"link":"/performance.sql","title":"Performance"}]}' AS menu_item,
'{"title":"Examples","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg","submenu":[{"link":"/examples/tabs/","title":"Tabs","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg"},{"link":"/examples/layouts.sql","title":"Layouts"}]}' AS menu_item,
'{"title":"Examples","size":"sm","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg","submenu":[{"link":"/examples/tabs/","title":"Tabs","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg"},{"link":"/examples/layouts.sql","title":"Layouts"}]}' AS menu_item,
'Official [SQLPage](https://sql-page.com) documentation' as footer;
```
Loading
Loading