reload-page-with-a-flash.go 1.2 KB

123456789101112131415161718192021222324252627282930
  1. package advanced_functions
  2. import (
  3. "github.com/qor5/docs/docsrc/examples/e00_basics"
  4. "github.com/qor5/docs/docsrc/generated"
  5. "github.com/qor5/docs/docsrc/utils"
  6. . "github.com/theplant/docgo"
  7. "github.com/theplant/docgo/ch"
  8. )
  9. var ReloadPageWithAFlash = Doc(
  10. Markdown(`
  11. The results of an ~web.EventFunc~ could be:
  12. - Go to a new page
  13. - Reload the whole current page
  14. - Refresh part of the current page
  15. Let's demonstrate reload the whole current page:
  16. `),
  17. ch.Code(generated.ReloadWithFlashSample).Language("go"),
  18. utils.Demo("Reload Page With a Flash", e00_basics.ReloadWithFlashPath, "e00_basics/reload-with-a-flash.go"),
  19. Markdown(`
  20. ~ctx.Flash~ Object is used to pass data between ~web.EventFunc~ to ~web.PageFunc~ just after the event func is executed. quite similar to [Rails's Flash](https://api.rubyonrails.org/classes/ActionDispatch/Flash.html).
  21. Different is here you can pass in any complicated struct. as long as the page func to use that flash properly.
  22. ~er.Reload = true~ tells it will reload the whole page by running page func again, and with the result's body to replace the browser's html content. the event func and page func are executed in one AJAX request in the server.
  23. `),
  24. ).Title("Reload Page with a Flash").
  25. Slug("basics/reload-page-with-a-flash")