Skip to content

Commit 898557d

Browse files
committed
✨ Add docs for the new Session tag
1 parent 19f2ddb commit 898557d

File tree

7 files changed

+170
-0
lines changed

7 files changed

+170
-0
lines changed

assets/examples/session-dump.png

20.5 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Session:Dump
3+
overview: The session:dump tag is used to inspect the user session for debugging purposes.
4+
id: d1ef36ac-7d21-40b2-a7fc-b53a0be3c79c
5+
---
6+
## Usage
7+
8+
You can dump the contents of the user session to aid with development.
9+
```
10+
{{ session:dump}}
11+
```
12+
13+
It will be injected into the rendered page in your browser.
14+
15+
<div class="screenshot">
16+
<h3>Preview</h3>
17+
<img src="/assets/examples/session-dump.png" alt="Session Dump">
18+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Session:Flash
3+
overview: The session:flash tag is used to store data for a single request.
4+
id: 29957a36-a15a-4fd0-9342-b829b6235fea
5+
---
6+
## Usage
7+
8+
Flash data is only kept for a single request. It is generally used for success/failure messages that remove themselves automatically.
9+
10+
Setting and retrieving flash data works in exactly the same fashion as regular session data.
11+
```
12+
{{ session:flash success="true" message="You did it!" }}
13+
```
14+
15+
The next (and only next) request will then have those variables available for you.
16+
17+
```
18+
{{ session:success }} ~> true
19+
{{ session:message }} ~> You did it!
20+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Session:Flush
3+
overview: The session:flush tag is used to clear the entire user session.
4+
id: 1f522665-9fc2-4c9f-9594-04a518c51b39
5+
---
6+
## Usage
7+
8+
Data set in the session will be available in all requests until such time that the session is cleared, either over time (sessions eventually expire) or intentionally.
9+
10+
The flush tag will wipe the entire session. Keep in mind this will also sign a user out if they're signed in.
11+
12+
```
13+
{{ session:flush }}
14+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Session:Forget
3+
overview: The session:forget tag is used to remove data from the user session.
4+
id: be024503-9796-4f2f-9c75-548e2ea09cec
5+
---
6+
## Usage
7+
8+
Data set in the session will be available in all requests until such time that the session is cleared, either over time (sessions eventually expire) or intentionally.
9+
10+
Remove variables from the session by passing a collection of keys into the tag.
11+
```
12+
{{ session:forget keys="likes|referral" }}
13+
```
14+
15+
Or you can wipe the entire session with the flush tag. Keep in mind this will also sign a user out if they're signed in.
16+
17+
```
18+
{{ session:flush }}
19+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Session:Set"
3+
overview: "The session:set tag is used to store and persist data in the user session."
4+
id: 90796c5b-6b11-4b02-9e6b-fd70211c825a
5+
---
6+
## Usage
7+
8+
Data set in the session will be available in all future requests until such time that the session is cleared, either over time (sessions eventually expire) or intentionally. Session variables can be retrieved with the base [session](/tags/session) tag.
9+
10+
This can be used for many different things. For example, you could set a set a variable if a user has filled out a special survey form.
11+
12+
```
13+
{{ session:set entered_survey="true" }}
14+
```
15+
16+
Later you could decide to show the user has filled out the form.
17+
18+
```
19+
{{ session }}
20+
{{ if entered_survey }}
21+
<p>You already filled out the form.</p>
22+
{{ /if }}
23+
{{ /session }}
24+
```
25+
26+
## Multiple Variables
27+
28+
You can set multiple variables at once, and reference interpolated data just like all other tags.
29+
30+
```
31+
{{ session:set likes="hats" :referral="get:ref" }}
32+
```
33+
34+
## Tag Pair
35+
This tag is also available as a pair, which allows you to display any data immediately if you so desire.
36+
37+
```
38+
{{ session:set likes="books" }}
39+
<p>You like {{ likes }}, huh?</p>
40+
{{ /session:set }}
41+
```
42+
43+
## Setting Array Data
44+
45+
You can even set array data with dot notation.
46+
47+
```
48+
{{ session:set likes.books="true" likes.hats="true" }}
49+
```
50+
51+
## Forgetting Data
52+
53+
You can remove data from the session [session:forget](/tags/session-forget), and flush the entire session with [session:flush](/tags/session-flush).

content/collections/tags/session.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Session
3+
description: "Get, set, and forget data in your user's session."
4+
overview: Sessions provide a stateless way to store information about the user across requests. The session tag will let you get, set, and forget session data.
5+
is_parent_tag: true
6+
id: c15836c2-808d-4260-9d01-e5a569da5b5a
7+
---
8+
## Retrieving Session Data
9+
10+
You can use `{{ session }}` as a tag pair to access all the data inside your user's session.
11+
12+
```
13+
{{ session }}
14+
{{ message }}
15+
{{ /session }}
16+
```
17+
18+
```.output
19+
Welcome to the session.
20+
```
21+
22+
You can also retrieve single variables with a single tag syntax.
23+
24+
```
25+
{{ session:message }}
26+
```
27+
28+
## Aliasing
29+
30+
If you need extra markup around your session data, you can _alias_ a new child array variable.
31+
32+
```
33+
{{ session as="sesh" }}
34+
{{ sesh }}
35+
{{ message }}
36+
{{ /sesh }}
37+
{{ /session }}
38+
```
39+
40+
## Setting and Forgetting
41+
42+
You can set data with [session:set](/tags/session-set), flash data with [session:flash](/tags/session-flash), forget it with [session:forget](/tags/session-forget), and flush the entire session with [session:flush](/tags/session-flush).
43+
44+
## Debugging
45+
46+
If you want to peek into the session and check the data, do so with with [session:dump](/tags/session-dump) or the [debug bar](/debugging#debug-bar).

0 commit comments

Comments
 (0)