After reading this article you will know:
- What request variables are
- How to setup a request variable
- How to use request variables
When a web browser loads a web page, it sends a request to the server for the page. The most common request is a GET request, which simply requests a web page. When a user performs such a request, they send certain variables back to the server, such as their IP address, what browser they're using and what web page they came from. You can save these variables in a custom model by setting up a request variable!
Whenever you set up a request variable, a custom model is assigned or generated for the page. The custom model can be viewed and altered at the custom models overview of your app (Tools > Custom Models). The default properties are:
- client_cert_info (collection of other attributes)
- params (collection of other attributes)
- headers (collection of other attributes)
The standard request variable's custom model's JSON is as follows:
How to create request variables
You can only create request variables on pages and endpoints, so let's start by opening one up. If you don't have any endpoints yet, you can find out how to create them here: HowTo create a web page?
Once you've opened the endpoint you want to add a request variable to, scroll to the bottom of the form and enter in "Request variable as".
You can now press enter and that'll be that! That's all you need to do to use them. You might notice that a new input variable has been created, named the same as the request variable. This input variable has been automatically generated, as by pressing enter without selecting our own, Betty Blocks was forced to generate a custom model for our request variable to use. You can also create you own by editing the request variable.
Using request variables
You can use your request variables just like any other custom model. You can access them using the variable browser.
You can use your request variable in Liquid the same way you would in a text expression by removing the var: and surrounding it with curly brackets, like so
You can learn more about Liquid here: HowTo use the Liquid Template Language to display dynamic content on your templates