Comments? Email me: tar@durge.org |
HitopliveDoing it on the fly...Right, now for some of the fun stuff. You should now know enough to be able to create pages using hitop. You can keep on doing this, creating the html files from the hitop files, or you can do it in a far funkier way... Hitoplive is a nice little tool that means you can have the server create your webpages as they are requested. And how do you achieve this amazing feat? Well, you change the extension on your files to live instead of hitop, and that's it! It really is that simple - create your file as normal, save it as bob.live, then view it as http://www.yourserver.org/bob.live. All this depends, of course, on your webserver being set up to do so. If not, it is still possible to use hitoplive, but it isn't as nice. Full details on setting up your webserver or using hitoplive via cgi are in the Hitop FAQ. Why would you want to? Well, I'm glad you asked... Generating web pages on the fly, so to speak, enables you to do a variety of funky stuff. Your pages can personalize themselves to the viewer, they can read in data from a database as and when required, and all in all, have a funky time... Regular readers of this guide will notice the new login box that has appeared to the left. It doesn't do much, but if you do login, the pages will automagically display your name in that space! More details on this astounding feat will be in the next installment of this guide. For now it is enough to know that just in time web pages enable you to create a better user experience. So, how can we take advantage of hitoplive? There are many ways, but
(IMHO) the three most important are:
There are a variety of functions that hitop provides for you. The full list of these string functions is available on hitop.org's reference pages. We will be looking at the date handling functions, in conjunction with an inbuilt hitop variable, DATE. What we are going to do is create a page that will tell us the date 50 days hence. We need to use functions as it isn't just a case of adding fifty days, as we need to worry about months, years etc. First of all, we need to know how to get the present date, and convert it to a form we can use in a mathematical expression. Then we need to add 50 days to this date, then reconvert it to a normal date. Phew! The code we will use looks scary, but isn't that bad really... It is:
Now don't get scared... I've thrown you in at the deep end a bit, but we will go through the code and explain it. First of all, we are using a @GET. This is fetching the inbuilt variable DATE for us, which you can see in the name= section. Now to explain the functions... The DATE is the
date variable. The colon indicates the end of the name of that variable, and
enables us to put datetodaynum() after it. This converts the date (which is
provided in YYYY-MM-DD format) to a single number. The ${...} around that
shows it is a variable all on its own, to which we then add 50, the +50 part.
The two apostrophes seperate this little subsection from the rest.
This bit
does the sum for us. The last variable actually looks something like 123456+50
when we finish with it, and the eval() part looks at this and does the
addition. Again, the ${...} around that shows it is a variable all on its own,
and the two apostrophes seperate this little subsection from the rest.
This
section takes the number eval() returns, and converts it back to a date, which
we can then show on screen! Phew!
This code in action looks like this: 2009-01-21. However, this is a little limited. Suppose we want to know the date 200 days from now? Well, we can use the magic of hitop to do this, via a form. The form code is: We also need a slight change to the
expression we are using: 50 must be replaced with ${FORM_num} which is how
hitop passes form variables (i.e. the name of the input in the form, with
FORM_ prefixed). The last thing we need is a @SET to give the variable
FORM_num a value if the form hasn't been filled in. DEFAULT (below) tells
hitop not to use this if FORM_num already has a value. This means the form below should appear and do your
bidding... The date next to it should change to whatever you want. Oh, and if
you type in a word, prepare to live in 1906.
|