Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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