Hello World !Open a file with some text editor.
Below is the code :
2: A string is always surrounded by " ". This line will output the string. We'll see functions later.
! Before release 1.0 final, to output something, you have to put this on a simple line :
3: Ending tag. If you dn't put it, Cws will output an error message.
Hello World !
Note that you also may train with the command-line tool, you just don't have to open and close <#cws tags.
2: This line of code will concatenate the three strings Hello, [space] and World ! It will then output "Hello World !"
3: Ending tag
Hello World !
VariablesA variable is prefixed by a '$' char, like in perl. They are case sensitive. The first char after the '$' has to be either a letter [a-zA-Z] or an underscore [_], the next ones can be letters, underscores and digits.
In the current version (1.0), variables are only strings. It means that if you try to put a number, it will be translated into a string.
3: Gets the value of a var already set, Home
4: Gets the value of an unset var, home (because it's case sensitive)
With correct case: /home/groups/c/ce/celsiusws
With incorrect case:
FunctionsFunctions are prefixed with a '@'.
Function arguments are separated with a comma and may be whatever you put within one code line. (except if/while/for...)
To get a whole list of available functions, please got to functions page
Depends on the content of footer.cws file
Here's another piece of code, illustrating composed functions
If GET_page is "../file.html", then it will include "..file.html". If cws can't open this file, it will return an empty string ad an error message.
Content of file named by GET_page's value, with suppressed '/'.
Get and Cookie varsConsider this url: http://celsiusws.sf.net/index.cws?page=doc&id=5
Get vars is the part after the '?'
At startup, and only if Cws is used as cgi, get vars will be evaluated, following the data provided after the '?'.
It's fairly simple and securised with Cws. In your scripts, you will be able to access these >variables with $GET_[subname], where [subname] is the name of the var you need. For "page=doc&id=5", $GET_page will contain "doc" and $GET_id will contain "5"
- if GET_page is set, includes this path after securising it
- if not set, includes file "data/index"
and assigns this value to "data"
3: If the requested file does not exist, and then "data" does not contain anything, will assign the contain of file "data/404error" to data
4: Outputs the content of "data"
In this script, we used the "if_null" and "if_not_null" functions, which are simple conditions functions, for in the 1.0 version we don't have other conditions. See next chapter ;)
Cookie vars are available with $COOKIE_name_of_cookie. A function "setcookie" is available to set them.
ConditionsIn the current version, 1.0, there are no conditions, except what we've seen just before. I think it should be ok for version 1.1
These conditions are functions, so they have to be prefixed with a '@'.
They take two or three arguments as input.
The first argument is a variable.
Consider this functions like this : if_not_null($condition, true, false)
4: This function is precisely the opposite of the first one. if $foo is null, the it will evaluate the second argument, and vice-versa
5: You also may put only two args to one of these functions, it this case, if result is false, it won't return anything.
foo var is not null
foo var is not null
[depends on GET_request's value]
User FunctionsThere are currently no user-defined functions in Cws, but you can simulate them.
We have seen before that you can store the content of an included file into a variable.
Note that files do not HAVE to return strings, they also can modify variables.
1.0.1 is outI've just released the 1.0.1
I'm now working on a CMS to demonstrate that Cws is yet powerful enough to build a website.
Working on docI'm currently building documentation files. And, more precisely, function's documentation
First final releaseThe first final release has been done now. Get it on CelSius project's page
Copyright ©2006 CelSius WS project. Total or partial copy is forbidden.|
Current CWS version is : 1.0.1