2. Conditional Programming

Conditional programming with WebDNA

numero = 154
interpreted = N
texte = Part 1 was far too easy. Now, let's see something much more complicated: we will introduce a condition. We will show something on the page if today is Friday (for example). First, we need to get today's day: [date %A]
[showif [date %A]=Friday]Today is the last day of work this week![/showif]
If your server's clock is on time, and if the day is really Friday, you will see the message. Otherwise, you will see.... nothing. What if we want to see a message if today is NOT Friday? Several ways:
[showif [date %A]=Friday]Today is the last day of work this week![/showif][showif [date %A]!Friday]Too bad![/showif]
Here "!" means "different from", or "is not equal to". And now we find something extremely interesting with WebDNA: you have several ways to do the same thing, because WebDNA is very flexible. You can do exactly the same thing with this code:
[showif [date %A]=Friday]Today is the last day of work this week![/showif][hideif [date %A]=Friday]Too bad![/hideif]
or using an if/then style statement:
[if "[date %A]"="Friday"][then]Today is the last day of work this week![/then][else]Too bad![/else][/if]
image >>> Next page... Part 1 was far too easy. Now, let's see something much more complicated: we will introduce a condition.

We will show something on the page if today is Friday (for example). First, we need to get today's day: [date %A]
[showif [date %A]=Friday]
Today is the last day of work this week!
[/showif]

If your server's clock is on time, and if the day is really Friday, you will see the message. Otherwise, you will see.... nothing.

What if we want to see a message if today is NOT Friday? Several ways:
[showif [date %A]=Friday]
Today is the last day of work this week!
[/showif]
[showif [date %A]!Friday]Too bad![/showif]

Here "!" means "different from", or "is not equal to".

And now we find something extremely interesting with WebDNA: you have several ways to do the same thing, because WebDNA is very flexible. You can do exactly the same thing with this code:
[showif [date %A]=Friday]
Today is the last day of work this week!
[/showif]
[hideif [date %A]=Friday]Too bad![/hideif]

or using an if/then style statement:
[if "[date %A]"="Friday"]
[then]
Today is the last day of work this week!
[/then]
[else]
Too bad!
[/else]
[/if]


image
>>> Next page... Christophe Billiottet

DOWNLOAD WEBDNA NOW!

Top Articles:

Related Readings:

3. Passing Data from a Form

Passing data from a form and retrieving it using WebDNA...

1. Learn WebDNA Programming

Learning WebDNA programming: the very basics...

4. Password Protecting

How to password-protect a page using WebDNA...

2. Conditional Programming

Conditional programming with WebDNA...

5. Writing Files

How to write a file using WebDNA...

6. Working with Databases

Working with WebDNA database...