Skip to content

Commit 5d7edcb

Browse files
author
Mykolas Mankevicius
committed
Add docs
1 parent 124f021 commit 5d7edcb

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.MD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dynamic Forms in static pages for ![statamic](https://raw.githubusercontent.com/Neophen/statamic-dynamic-token/master/public/statamic-logo.png)
2+
3+
Want static caching in statamic? And still want to have dynamic forms? for e.g.
4+
5+
![dynamic form in static page](https://raw.githubusercontent.com/Neophen/statamic-dynamic-token/master/public/dynamic_in_static.png)
6+
7+
Just add a `{{ dynamic_token }}` to your layout file just before `</body>` tag.
8+
then add an `APP_URL=site.com` to your `.env` file
9+
10+
### Installing
11+
Copy the `DynamicToken` into your `site/addons` folder.
12+
### How does this work?
13+
First off, if `javascript` is disabled this won't work. We will add this functionality later. On page load it will get a fresh csrf token and update all your forms with it. It will automatically update the token every 15 minutes.
14+
##### There are two parts:
15+
###### 1st:
16+
The `{{ dynamic_token }}` inserts a bit of javascript into your static html file, which allows it to pull a new `csrf` token and update all `<form>` tags which have an `<input name="_token">`, this applies to all `{{ form:create }}` tags, or any form if you add `<input name="_token">` to your normal forms.
17+
###### 2st:
18+
A simple controller, note you might need to exclude `/!/DynamicToken` from csrf setting like
19+
Disable CSRF verification by adding `/!/DynamicToken` to the `csrf_exclude` array in `site/settings/system.yaml`. Don't worry we check that the referrer is comming from your `APP_URL`.
20+
21+
### Gotchas
22+
If you've changed your api denominator, you will need to modify `$route = '/!/DynamicToken/refresh';` in the `DynamicToken/DynamicTokenTags.php` file. The default statamic denominator is `/!/`;

public/dynamic_in_static.png

59 KB
Loading

public/statamic-logo.png

4.21 KB
Loading

0 commit comments

Comments
 (0)