Now we want to put all the things together and extend our example to show undreamed-of possibilities. We want to show the user not only the current time, but also the time when he last visited this page.
To do so we first have to extend our template so that it will show the time of the last visit when available:
<html>
<body>
<h1 <?style style="<%style%>"?>>Current date: <%currentDate;required;text/plain%></h1>
<?lastVisit <h1 <?style style="<%style%>"?>>Last visit: <%lastVisit%></h1>?>
</body>
</html>Upload and check if the page looks exactly as before. Projector should not throw any exception as we used the newly introduced variable lastVisit as a condition and as such it gets optional. We remember that if it is not set, the marked block gets skipped.
Now we want to fill this variable with an appropriate value. This can be achieved by using the cookie store. We want to save the current time to a cookie when the user calls the page. This saved time will be displayed in the subsequent page calls. As a cookie is stored on the client machine on a per user basis, this value can be displayed to each individual user.
<?xml version="1.0" encoding="UTF-8" ?>
<process first-step="formatDate">
<description>
<output>
<state>ok</state>
<result name="welcomePage"
description="composedPage"
content-type="text/html"
presentable="true" />
</output>
</description>
<step id="formatDate" processor="dateFormatter">
<load parameter="date">
<value processor="system" result="currentDate"/>
</load>
<load parameter="timeFormat">
<string>medium</string>
</load>
<save result="output" key="currentDate"/>
<route state="ok" step="compose" />
</step>
<step id="compose" processor="hello">
<load parameter="currentDate">
<value key="currentDate"/>
</load>
<load parameter="lastVisit">
<value store="cookie" key="date"/>
</load>
<load parameter="style">
<string>color:red;font:italic;</string>
</load>
<save result="output" store="output"
key="welcomePage" presentable="true"/>
<route state="ok" step="updateCookie" />
</step>
<step id="updateCookie" processor="echo">
<load parameter="input"><value key="currentDate"/></load>
<save result="output" store="cookie" key="date"/>
<route state="ok" return="ok" />
</step>
</process>We’ve added a new step to store the current date in the cookie store. This is done by using the Echo processor. This processor is really simple but also useful: It simply echoes the value loaded to the parameter input to the result with the key output. We can use this to store the rendered date to the cookie store using the key date. This key is used in the adopted compose step to access the previously stored value.
If you reload the page, you will see no difference at first sight as the cookie just gets stored and is not yet present. But if you reload the page, you will see not only the current time, but also the time of your last visit of this page:

You can also store result to other stores, but with different effects as the scope of the stores differ. We can modify the template to show some other scopes:
<html>
<body>
<h1 <?style style="<%style%>"?>>Current date: <%currentDate;required;text/plain%></h1>
<?yourLastVisit <h1 <?style style="<%style%>"?>>
Your last visit: <%yourLastVisit%></h1>
?>
<?anybodysLastVisit <h1 <?style style="<%style%>"?>>
Anybodys last visit: <%anybodysLastVisit%></h1>
?>
<?lastVisitSinceRestart <h1 <?style style="<%style%>"?>>
Last visit since restart of Projector: <%lastVisitSinceRestart%></h1>
?>
</body>
</html>Now update the process definition that all these new parameters get loaded with the appropriate values:
...
<step id="compose" processor="hello">
<load parameter="currentDate">
<value key="currentDate"/>
</load>
<load parameter="yourLastVisit">
<value store="cookie" key="date"/>
</load>
<load parameter="anybodysLastVisit">
<value store="repository" key="/files/lastVisit.txt"/>
</load>
<load parameter="lastVisitSinceRestart">
<value store="cache" key="lastVisit"/>
</load>
<load parameter="style">
<string>color:red;font:italic;font-size:16px;</string>
</load>
<save result="output" store="output"
key="welcomePage" presentable="true"/>
<route state="ok" step="updateCookie" />
</step>
<step id="updateCookie" processor="echo">
<load parameter="input"><value key="currentDate"/></load>
<save result="output" store="cookie" key="date"/>
<save result="output" store="repository" key="/files/lastVisit.txt"/>
<save result="output" store="cache" key="lastVisit"/>
<route state="ok" return="ok" />
</step>
...