On-Rev scripting allows us to have scriptable web pages. This means our web pages can be scripted as they are served, so they are dynamic instead of static. However this still requires HTML tags to be inserted into the page.
The revTalk "put" command is used to display data on the web page, when used in an irev file.
e.g.
put the long date
or
put "<h1>" & tHeader & "</h1>"
But what if you want a more complex mix of HTML & revTalk?
As an example, on my web site I have text files with lists of related links. These are in the format of one link per line, with the name of the linked page and the address of the linked page separated by tabs. When the page is opened by a browser, I want the revTalk to loop through the lines of the relevant links file, getting the name and address for each entry and constructing a valid HTML link.
These links have to be in the following format:
<a href="page_address">Page Name</a>
so it's a mix of HTML and Rev variables, with quotes around the page address.
This can be constructed purely using revTalk, but it gets a bit messy. Let's see what it looks like if we build a command that has two parameters: the page address and the page name, and uses them to build a link and display it.
<?rev
command constructLink pAddress, pName
put "<a href=" & quote & pAddress & quote & ">" & pName & "</a>" into tLink
put tLink
end constructLink
?>
So it's not too bad, but fiddling with quotes is always a pain, and there is too much chance of getting them unbalanced.
Now let's look at the same function in an iRev page where it mixes HTML & revTalk:
<?rev command constructLink pAddress, pName ?>
<a href="
<?rev put pAddress ?>
">
<?rev put pName ?>
</a><br />
<?rev end constructLink ?>
As you can see, the revTalk sections are only single lines, interspersed with standard HTML lines.
Now that is a fairly simple example, and it's really a matter of preference which way you do it.
But how about when you want to display different things based on an "if" statement.
<?rev if tHour >= 12 then ?>
Good afternoon. <br />
I hope your day has been going well.
<?rev else ?>
Good morning. <br />
What are you going to do today?
<?rev end if ?>
Again, a simple example, but it shows a very useful technique. This can be used to change the display, to do multi-page forms etc.
Until next time,
Sarah