4

You sometime want to pass specific info from one page to another.

How do you do that with twig and are there explicit Craft methods to do this? Can you do this without exposing the variable in the URL?

6

You're options are:

  1. Adding it as a parameter in the querystring (e.g. domain.com?key1=value1)

  2. Submitting it though a form and grabbing the value from POST.

  3. Setting the value in a cookie and retrieving it on the next page using something like this plugin.

  4. Writing a plugin with a Twig function that wraps Craft's craft()->userSession->setFlash() method, which will store a key->value pair in session for exactly one request. You can retrieve the value via craft.userSession.getFlash().

Note that there are limitations to the size and complexity of the data you can pass along with all of these, but especially options 3 and 4, so it's best to stick with simple strings.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.