Skip to content

Commit af5428d

Browse files
First commit
1 parent 07accf3 commit af5428d

15 files changed

+1836
-0
lines changed

book.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[book]
2+
authors = ["tercmd"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "HTMXify"
7+
git_repository_url = "https://github.com/htmxify/docs"
8+
git_repository_edit_url = "https://github.com/htmxify/docs"
9+
cname = "https://htmxify.com"

src/SUMMARY.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Summary
2+
3+
- [Intro](./intro.md)
4+
- [Extensions](./extensions.md)
5+
- [inline-template](./extensions/inline-template.md)
6+
- [local-storage](./extensions/local-storage.md)

src/extensions.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Extensions
2+
3+
HTMXify currently has the following extensions:
4+
- [inline-template](./extensions/inline-template.md), an extension that uses Handlebars to compile templates, allowing the use of JSON APIs in HTMX.
5+
- [local-storage](./extensions/local-storage.md), an extension that allows using values from localStorage as request headers and setting values in localStorage as response headers

src/extensions/inline-template.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# inline-template
2+
3+
This extension uses Handlebars to compile a template passed in using an attribute and provides it the context of a JSON response.
4+
5+
## Note
6+
Please load Handlebars from a CDN like [cdnjs](https://cdnjs.com/libraries/handlebars.js) or [jsDelivr](http://www.jsdelivr.com/#!handlebarsjs).
7+
8+
## Attributes
9+
### `data-template`
10+
The value of this attribute should be a Handlebars template.
11+
12+
#### Example
13+
14+
JSON:
15+
```json
16+
[{
17+
"content": "Hello World!",
18+
"author": {
19+
"username": "tercmd",
20+
},
21+
}]
22+
```
23+
24+
HTML:
25+
```html
26+
<div hx-get="/api/messages" data-template="{{[0].author.username}} said {{[0].content}}" hx-trigger="load" hx-ext="inline-template"></div>
27+
```
28+
29+
Rendered content:
30+
```plaintext
31+
tercmd said Hello World!
32+
```
33+
34+
> The use of `[0].content` is important because the Handlebars template is accessing the 0th element of the context provided, which is the response itself.

src/extensions/local-storage.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# local-storage
2+
An extension to append request headers with values from localStorage.
3+
4+
## Attributes
5+
### `data-ls-item`
6+
This is the key of the item in localStorage.
7+
### `data-ls-header`
8+
This is the name of the header which is added to requests.
9+
10+
## Example
11+
```html
12+
<div hx-get="/api/..." data-ls-item="auth-token" data-ls-header="Authorization" hx-trigger="load"></div>
13+
```
14+
15+
This code sends a request with the header `Authorization: Bearer ...` (this token is stored in localStorage)

src/intro.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Intro
2+
3+
HTMXify is a set of extensions for [HTMX](https://htmx.org).
4+
5+
{{ #include extensions.md }}

0 commit comments

Comments
 (0)