Unlike some other web-languages, such as PHP, cookies are not implicitly treated as variables. Instead, LXP maintains
a separate list of cookies in addition to its list of variables. This is done to ensure that methods that should apply to
cookies always do, and to prevent the collision of variable names and cookie names.
Therefore, to display a cookie, use the <putcookie> tag, as shown in Example 13-7.
Example 13-7. Displaying a cookie value
<lxp>
Your cookie "user" is set to: <putcookie name="user" />
</lxp>
If you wish to substitute the value of a cookie into an LXP attribute, you might think you could do so with the same
dollar sign notation used to substitute variable values. However, this introduces a point of ambiguity between cookie
values and variable values. Therefore, cookie values may be accessed through the special
cookies LXP object.
Example 13-8. Substituting cookie values
<lxp>
<setvar welcome_msg="Welcome, @cookies.user!" />
<if cookies.user>
<putvar name="welcome_msg" />
</if>
</lxp>
As of LXP 0.8, for backwards compatibility, if a variable is not found with a specified substitution name (e.g.,
$my_cookie), LXP will search the list of cookies for a cookie with that name. This
behavior is scheduled to either be removed (or be made configurable) in future versions of LXP, however.