Home > Blockchain >  Pass data to template with redirect() in Statamic
Pass data to template with redirect() in Statamic

Time:01-19

I've got a form in Statamic, and I want to pass some data back to it on submission to show a nice 'All good' message, e.g:

return redirect()
    ->back()
    ->with(['form_success' => true]);

Unfortunately the template completely ignores the contents of ->with() in the template.

Is there a way to get it to listen to with, or is there another way of doing this?

CodePudding user response:

Whenever you return like that from a POST route, I believe the with data is also available in the session.

So in Antlers, you should be able to do something like this:

{{ session:form_success }}

And to display something in your template depending on if form_success is available, you can do this:

{{ if {session:has key="form_success"} }}
    <p>Success!</p>
{{ /if }}

Hopefully this will work for you!

  • Related