New messages Members Forum rules Search
  • Page 1 of 1
  • 1
Forum moderator: kostova  
uCoz Support Forum by uCozers » uCoz » Additional Features » Can some one here explain me conditional operators? (sml[answered])
Can some one here explain me conditional operators?
YoshoDate: Friday, 2009 October 02, 5:42 AM | Message # 1
Font size: A | A |
Sergeant
Group: User
Message: 39
[ ]
Offline
can some one here explain me conditional operators, how to use and etc
 
kostovaDate: Friday, 2009 October 02, 6:04 AM | Message # 2
Font size: A | A |
Colonel
Group: Administrator
Message: 268
[ ]
Offline
<?if($YOU_ARE_TALKING_ABOUT_UCOZ_OPERATORS$)?>

Then here's a small explanation. Ucoz if/else operators are really useful! Basically they output information if something is present. But if it is not present, it will either output something else or nothing at all.

example input:

Code
<?if($USER_LOGGED_IN$)?>
Hello $USERNAME$!
<?else?>
Not a member? Register Now!
<?endif?>

example output (logged in):
Hello Yosho!

example output (not logged in):
Not a member? Register Now!

If/else operators always have to have the <?( and end with a )?>
The codes always have a $ and end with a $

<?else?>

<?if($YOU_ARE_TALKING_ABOUT_JAVASCRIPT$)?>
___I don't even know much about it. Sorry.
<?endif?>

<?endif?>

Edited Bykostova - Friday, 2009 October 02, 6:06 AM
 
YoshoDate: Friday, 2009 October 02, 6:05 AM | Message # 3
Font size: A | A |
Sergeant
Group: User
Message: 39
[ ]
Offline
i don't really understand this kind of tags <?endif?>
 
kostovaDate: Friday, 2009 October 02, 6:11 AM | Message # 4
Font size: A | A |
Colonel
Group: Administrator
Message: 268
[ ]
Offline
<?endif?> ends the operator function.

It has to be properly nested, basically closing it.
<?if($USER_LOGGED_IN$)?>
HELLO
<?endif?>

If you have multiple if/else operators inside if/else operators, it may get a little tricky.
<?if($USER_LOGGED_IN$)?>
<?if($USERNAME$='Yosho')?>Hello Yosho!<?else?>Hello $USERNAME$<?endif?>
<?else?>
Hello Guest
<?endif?>

It's color coded. Blue are the outlying if/else operators that need to be closed.
Red is inside the operators, and are closed ;]

Edited Bykostova - Friday, 2009 October 02, 6:11 AM
 
SamanaleDate: Friday, 2009 October 02, 10:20 AM | Message # 5
Font size: A | A |
Sergeant
Group: User
Message: 33
[ ]
Offline
Conditional blocks allow to output (to process) or not to output (not to process) some particular fragment of a template depending on various conditions. These conditions are applied to the values of special template variables (such as $GROUP_ID$). A conditional block is opened by the '<?if()?>' operator and closed by the '<?endif?>' operator. Several conditional blocks can be nested.

Conditional operators have the following syntax:
<?if($VARNAME$)?>true_code<?else?>false_code<?endif?>

* $VARNAME$ - name of a special variable, the value of which will be compared with a condition.
* true_code – HTML code to be displayed if a specified condition is true (can be empty if only negative test is necessary).
* false_code – HTML code to be displayed if a specified condition is false (can be absent together with '<?else?>' operator if only positive test is necessary).

Some examples:
<?if($USER_LOGGED_IN$)?>Hello $USERNAME$<?endif?>

<?if(!$USER_LOGGED_IN$)?>You are just a GUEST<?endif?>

<?if($USER_LOGGED_IN$ and $USERNAME$='Andrew')?>Hello Andrew<?endif?>

<?if($MODULE_ID$='load' and $PAGE_ID$='category')?>Categories page<?else?>Other page<?endif?>

* = - full coincidence of the value with the operand (case sensitive string comparison);
* ! - mismatch of the value with the operand (negation of case sensitive string comparison);
* > - the value is numerically greater than the operand (numerical comparison of integer or fractional decimal numbers);
* < - the value is numerically less than the operand (numerical comparison of integer or fractional decimal numbers);
* % - integer remainder of the division of the value by the operand (see note **);
* & - bitwise "AND" between the value and the operand (see note **);

* && (and) – logical AND;
* || (or) – logical OR;

* substr($STRING$,pos,num) - getting of a substring of the string $STRING$, starting from the position pos, of the length num characters;
* strpos($STRING$,'substring') - getting of a position of the substring substring in the string $STRING$;

*The variable's value is considered to be false (not true) if it is empty or equal to '0' (i.e. '4', 'Hello', '00' or '0.0' are considered to be true).

** For the operations '%' and '&' an operand can be specified either as one number or as two numbers separated by 'equals' character ('='). In the first case the result of the corresponding operation will be tested against non-zero value, i.e. '%2' means 'remainder of the division by 2 is not equal to zero'.
Examples:
You <?if($USER_LOGGED_IN$)?>have logged in as "$USERNAME$"<?else?>haven’t authorized yourself<?endif?>.
It outputs (having substituted $USERNAME$ by its value) You have logged in as "$USERNAME$". if $USER_LOGGED_IN$ is true, otherwise You haven’t authorized yourself.
<?if($USERNAME$='Hacker' || $USERNAME$='bad_boy' || substr($USERNAME$,0,4)='anti')?>No way, $USERNAME$!!!<?endif?>
It outputs (having substituted $USERNAME$) by its value No way, $USERNAME$!!! if $USERNAME$ equals to 'Hacker' or 'bad_boy', or begins with 'anti'.
<?if($POSTS$>50)?>***<?else?><?if($POSTS$>10.0)?>**<?else?>*<?endif?><?endif?>
It outputs ' *** ', if $POSTS$ is greater than 50, ' ** ', if it is greater than 10 and less than or equal to 50, and ' * ', if it is less than or equal to 10.
<?if($NUMBER$%2=1)?>odd<?else?>even<?endif?>
It outputs whether the value of $NUMBER$ is even or odd.

 
uCoz Support Forum by uCozers » uCoz » Additional Features » Can some one here explain me conditional operators? (sml[answered])
  • Page 1 of 1
  • 1
Search:


Copyrights uCozers 2009 - 2024 To TOP
Refresh Smileys Manager