Rule Action values can be retrieved dynamically using Velocity code in a Widget, Form, Container, Template, etc., using Velocity code. Shown below is an example of the “Set Response Header” Action that allows keys/values to be added to the response header:
A Rule Condition is not necessary when adding attributes to the response header. However, the Rule must be set to “ON”, a “Fire On” property must me set, the “Set Response Header” action must be chosen, and a key and value set. The “Fire On” rule property can be set to:
- Every Request
- Every Page
- Once per Visit
- Once per Visitor
- Every Request (must be used for File or image asset paths)
Retrieving Response Header Action Attributes using Velocity
This Action will set a key/value map in the response header. With this Action you will only need to send the key and the value as parameters. For example, you can add this the the request object: “ResponseHeaderkey”→“ResponseHeaderValue” where “ResponseHeaderkey” is the key and “ResponseHeaderValue” is the value.
You could later access this information from the response header. For example, with Velocity you can pass a key to retrieve the value using the following method:
$response.getHeader("key")
Following the example retrieves the value of the key called “ResponseHeaderkey” which had previously set in the Rule (see image above):
$response.getHeader("ResponseHeaderKey")
Example return: "ResponseHeaderValue"
Important Reminder: The Rule must be set to ON for the attribute to be added to the response header.