zcms:cookie tag can store and read cookies. The stored cookies can be retrieved using the zcms:use tag.
Attribute Definition mode The mode of cookie tag:
- read: will read the cookies.
- write: will write the cookie data.
expire Set the age or expiry of cookie
There are five predefined values:
- SESSION_END – The cookie will be expired at end of session. If no expiry is set, the default will be SESSION_END.
- ONE_DAY – The cookie will expire in one day.
- ONE_WEEK – The cookie will expire in a week.
- ONE_MONTH –The cookie will expire in a month.
- ONE_YEAR – The cookie will expire only after a year.
To set the cookie expire time custom one other than predefined use type “CUSTOM” and set the time in attribute
time Set the expiry of a cookie when the expiry type is “CUSTOM”. The time should be defined in seconds domain Set the domain of the cookie path Set the cookie path
Below an example of using the zcms:cookie. In the example the first cookie will expire after one day and the second cookie will expire after 20 seconds.
- In writing mode:
<zcms:cookie mode="write" expire="ONE_DAY"> <zcms:param name="data2" value="cookie1"/> </zcms:cookie> <zcms:cookie mode="write" expire="CUSTOM" time="20"> <zcms:param name="data6" value=" cookie2"/> </zcms:cookie
- In reading mode:
<zcms:cookie/> <div>data1 :<zcms:use name="cookie_data2"/></div> <div>data2 :<zcms:use name="cookie_data6"/></div>
The stored cookies can be retrieved by calling the name cookie_[cookie name]. In above example the cookie is retrieved by calling the name “cookie_data2”. The <zcms:cookie/> tag should be used in a page in order to read a cookie.