Skip to content

Commit 1265b5f

Browse files
author
Olivier Auverlot
committed
Adding an alias named contents to the html property of the shell-empty component
1 parent 215170e commit 1265b5f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_STORE
12
/target
23
sqlpage.db
34
.idea/

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,4 +1533,14 @@ so you can also [create your own shell component](custom_components.sql#custom-s
15331533
If you generate your own HTML from a SQL query, you can also use the `shell-empty` component to include it in a page.
15341534
Make sure you know what you are doing, and be careful to escape the HTML properly,
15351535
as you are stepping out of the safe SQLPage framework and into the wild world of HTML.',
1536-
json('[{"component":"shell-empty", "html": "<!DOCTYPE html>\n<html>\n<head>\n <title>My page</title>\n</head>\n<body>\n <h1>My page</h1>\n</body>\n</html>"}]'));
1536+
json('[{"component":"shell-empty", "html": "<!DOCTYPE html>\n<html>\n<head>\n <title>My page</title>\n</head>\n<body>\n <h1>My page</h1>\n</body>\n</html>"}]')),
1537+
('shell','
1538+
### Return data in a format other than HTML
1539+
If you create a RESTful API with SQLPage and the data format transmitted to the client is not HTML,
1540+
you can use an alias named `contents` to enhance the readability of your code.
1541+
This approach is particularly useful for returning data formats such as JSON or XML.
1542+
1543+
Remember to use the [http_header](component.sql?component=http%5Fheader) component beforehand to inform the client about the format of the data being sent.
1544+
For example, for XML, the correct [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) type should be `application/xml`.
1545+
',
1546+
json('[{"component":"shell-empty", "contents": "<?xml version=\"1.0\"?>\n <user>\n <account>42</account>\n <login>john.doe</login>\n </user>"}]'));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{{{~html~}}}
2+
{{{~contents~}}}
23
{{~#each_row~}}{{~/each_row~}}

0 commit comments

Comments
 (0)