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?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityYou 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?
You're options are:
Adding it as a parameter in the querystring (e.g. domain.com?key1=value1)
Submitting it though a form and grabbing the value from POST.
Setting the value in a cookie and retrieving it on the next page using something like this plugin.
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.