Conditional Operators - Additional Features - uCoz System management and tuning - uCoz Community
You logged in as Guest
Username/E-mail:
Recent messages · Members · Forum rules · FAQ · SEARCH Registration · Log in


We are in the second round! Let's keep voting!

Page 2 of 2«12
uCoz Community » uCoz System management and tuning » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
Conditional Operators
SunnyDate: Wednesday, 2008-03-26, 3:47 Am | Message # 1
Haunter
Group: Administrators
Messages: 2016
Awards: 121
Reputation: 139
Status: Offline
Conditional operators for noobs and professionals.

If you do not understand how conditional operators work and the information in the Control Panel is not enough for you, I will try to explain. First, you should believe, that it is very easy!

Conditional operators are special codes-symbols, which can perform certain scenarios (scripts). You can create an absolutely new option on your site that is not provided in the Control Panel.

First, you must understand and get used to the components of the script code. They are:

<?if($code$)?> – it is some condition (code), which points to the operator whom and what we are dealing with. We can mentally replace it by the phrase «If there is»;

<?else?> – it is the operator which will do what you say if the condition corresponds to the indicated ones. Replace it mentally by the phrase «If not»;

<?endif?> – it is the end of the conditional operator, replace it mentally by «The end»;


Now let’s examine an easy example from the Control Panel:

(from Page Editor)

<?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> You are a GUEST. Please, register. <?endif?>

In our language it means: «If there is an authorized user, then «Hello, his/her login!», if not, «Hello, guest!» and the end.»

Now the details.

What did we use?

We said to <?if($code$)?> operator that our script is intended for saying hello to authorized users. We put the following code instead of $code$ - $USER_LOGGED_IN$ , i.e. we said «If there is an authorized user - <?if($USER_LOGGED_IN$)?>». Then the information, available only to authorized users, follows. At the same time, we may use conditions if they do not correspond to the indicated ones, in our example it is Guests. Therefore, after the information for registered users we enter the information for guests.

We get
<?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> Hello, Guest!

Now we have just to close it.
<?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> Hello, Guest! <?endif?>

We can also exclude Guests and display information for registered users only. For this purpose we just do not use «If not». We get the following:

<?if($USER_LOGGED_IN$)?> We are glad that you have registered! <?endif?>

It means that only those who have logged in will see the phrase «We are glad that you have registered!».

Any code, specified as working for a certain module, can be a condition for the work of operators. In our case (Page Editor), the following examples can be used:

Login and logout:
<?if($USER_LOGGED_IN$)?> <a href="$LOGOUT_LINK$">LOG OUT</a> <?else?> <a href="$LOGIN_LINK$">LOG IN</a> <?endif?>

Days after registration:
<?if($USER_LOGGED_IN$)?> You are with us for $USER_REG_DAYS$ days! <?else?> Please, register. <?endif?>

And so on.


Conditions for a script can be changed by means of additional capabilities, supported by the operators. They are «=», «>», «<» signs. If necessary, the equated conditions are separated by a vertical line. After the sign, you say to the operator to whom the whole script is directed.

<?if($code$='condition')?> I can see this <?else?> And here I can see this <?endif?>

Or

<?if($code$='condition')?> The main thing is that I can see this <?endif?>

Example:

<?if($USER$='John')?> John, don’t forget to read e-mail every day. <?endif?>

It means «If there are usernames and there is John among them (='John'), then this is to be displayed to him…»

The same is with groups, names, gender, date etc.
More examples:

<?if($USER$='Mike' or $USER$='Lola')?> Mike and Lola, here is a secret link …. <?endif?>

Groups:
<?if($GROUP_ID$=3 or $GROUP_ID$=4)?> Moderators and Administrators, click on the ad here… <?endif?>

And so on.

However, operators can work in each other. Example:

<?if($USER_LOGGED_IN$)?> Hello $USER$! <?if($GROUP_ID$=3 || $GROUP_ID$=4)?> Don’t forget to click on the ads! <?endif?> <?else?> Please, register. <?endif?>

The script is the following: «If there are logged-in users, then Hello, if there Administrators and Moderators among them, then add Click on ads, if there are unregistered users, we ask them to register, and the end.»


The main thing is that you must think well how to write a script, what codes to use and whom they will be directed to. You may write anything, uCoz is very flexible!

Additional mini-info:


  • The number of <?if($code$)?> and <?endif?> must be the same.
  • <?else?> is necessary if we output information for those, who don’t meet the conditions, otherwise it is not needed.
  • Alternative conditions or and and (|| and &&) are supported.
  • Nesting of operators is supported.
  • Comparing of variables to each other is supported: <?if($VAR1$=$VAR2$)?>
  • The text must be in quotes when comparing: <?if($USER$='Mike') ?>


    I'm not "man", "sir" or whatever. I'm female!
    About signatures, screenshots etc...
  •  
    Igor-SousaDate: Wednesday, 2009-08-05, 6:53 Pm | Message # 16
    Constant
    Group: Checked
    Messages: 142
    Awards: 10
    Reputation: 16
    Status: Offline
    Quote (Armaros)
    You go and test it.
    Thanks for the reply, but a simple "yes" or "not" helps a lot. happy

    I've made grammar mistakes ?? Google's fault !!

    Time is the most valuable thing a man can spend.

     
    ArmarosDate: Wednesday, 2009-08-05, 7:08 Pm | Message # 17
    Haunter
    Group: Checked
    Status: Offline
    Quote (Igor-Sousa)
    Thanks for the reply, but a simple "yes" or "not" helps a lot.
    Testing before asking dumb questions helps us a lot.

    Tell me good reason why I need to test them in your place?
    It's you who needs them not me. It's your job to test things!

    SunnyDate: Friday, 2009-08-07, 4:42 Am | Message # 18
    Haunter
    Group: Administrators
    Messages: 2016
    Awards: 121
    Reputation: 139
    Status: Offline
    Just to stop this discussion - yes it should work if you enable HTML when adding an entry.

    I'm not "man", "sir" or whatever. I'm female!
    About signatures, screenshots etc...
     
    TommyDate: Saturday, 2009-08-22, 6:20 Am | Message # 19
    Experienced
    Group: Helpers
    Messages: 439
    Awards: 17
    Reputation: 23
    Status: Offline
    Hey,

    I used conditional operators to show the user's name, gender and his group in the block, but i could not show his/her Age, Last login time. I used the following code to display the User's gender when he/she login to my site.

    Code
    <?if($USER_LOGGED_IN$)?> Group - $USER_GROUP$<?endif?><BR>

    If i use the same code for Age it does not work.

    Code
    $_LOG_TIME$ ,  $_AGE$

    I need some help!!! wacko


    "I don't like to commit myself about heaven and hell - you see, I have friends in both places"
     
    SunnyDate: Tuesday, 2009-08-25, 5:03 Am | Message # 20
    Haunter
    Group: Administrators
    Messages: 2016
    Awards: 121
    Reputation: 139
    Status: Offline
    Vinothdazzlin, make sure the codes $_LOG_TIME$ and $_AGE$ are available in the template you are editing.

    I'm not "man", "sir" or whatever. I'm female!
    About signatures, screenshots etc...
     
    haseebahmed142Date: Friday, 2009-08-28, 5:04 Am | Message # 21
    Newbie
    Group: Users
    Messages: 6
    Awards: 0
    Reputation: 0
    Status: Offline
    i want that to hide full description from guest but not short detail in publisher page but i dont know how can you explain me step by step what code i need n where i have to paste that code.thanks in advance biggrin

    Added (2009-08-28, 5:04 Am)
    ---------------------------------------------
    anybody here to help me

     
    DartzDate: Friday, 2009-08-28, 5:09 Am | Message # 22
    Cookie Monster
    Group: Head Mod
    Messages: 5961
    Awards: 61
    Status: Offline
    This threads first post already explains step by step. As for where to place it, place it where you need the text to appear.


    *Yawn... drools on Renatus while sleeping...*
    CartmanDate: Wednesday, 2009-11-11, 8:11 Am | Message # 23
    Newbie
    Group: Users
    Messages: 7
    Awards: 0
    Reputation: 0
    Status: Offline
    I want to make a counter for counting for every user how many times they downloaded something from my catalog, and how many times the uploded something. I want to make rule that they only can download if they have enough uploads. Is it possible and how? Thx

    Message edited by Cartman - Wednesday, 2009-11-11, 8:11 Am
     
    SunnyDate: Wednesday, 2009-11-11, 8:34 Am | Message # 24
    Haunter
    Group: Administrators
    Messages: 2016
    Awards: 121
    Reputation: 139
    Status: Offline
    Cartman, you speak about File Catalog? The number of downloads is shown by default under each entry. The number of added entries (uploads) can be seen in user's profile.
    If you want to do this using conditional operators try $_LOAD_ENTRIES$ variable. It will be smth like this (you need to edit the corresponding File Catalog template):

    Quote
    <?if($_LOAD_ENTRIES$>10)?>download link<?else?>You don't have enough uploads<?endif?>

    I haven't tested it so try yourself.

    You can also do the following: adjust user group permissions and forbid Users to download. Then set Auto-transfer to Checked according to the number of File Catalog entries and allow Checked group to download.


    I'm not "man", "sir" or whatever. I'm female!
    About signatures, screenshots etc...
     
    CartmanDate: Wednesday, 2009-11-11, 3:07 Pm | Message # 25
    Newbie
    Group: Users
    Messages: 7
    Awards: 0
    Reputation: 0
    Status: Offline
    Sunny! Thank you! That's it! I love you! smile
     
    uCoz Community » uCoz System management and tuning » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
    Page 2 of 2«12
    Search: