Page 1 of 151231415»
uCoz Community » uCoz Modules » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
Conditional Operators
Posts: 9296
Reputation: 456
Message # 1 | 9:47 AM
Conditional operators for newbies 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?>


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


<?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?>

<?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 active on the forum anymore. Please contact other forum staff.
  • Kron_old
    Posts: 117
    Reputation: 52
    Message # 2 | 9:55 AM
    Question - answer
    When creating new pages, uploaded via FTP, $SITE_NAME$, $LOGIN_LINK$, $LOGOUT_LINK$ codes are displayed as text... Why don’t they work?

    $Codes$ work only on dynamic pages, i.e. pages, created in the Control Panel by means of "Create page" option. These $Codes$ don’t work on uploaded static pages with .html extension.
    How can I make alternative conditions, e.g. for $GROUP_ID$ code?

    <?if($GROUP_ID$=5 or ($GROUP_ID$=4 and $USER$='Alex'))?>...<?endif?>
    Are there operators, which allow a user to see in the list only the categories, to which he/she has access?

    It can be done by forming the list of categories manually, i.e. you check current group and output the necessary list of categories. At the next level, check against necessary section.
    $GROUP_ID$ doesn’t work in Tag Board template, why?

    Tag Board messages are cached, so you cannot use there dynamically variable codes.
    There is $USER_LOGGED_IN$ code. Is there $USER_LOGGED_OUT$ code?

    You should just add negation to the condition <?if(!$USER_LOGGED_IN$)?>

    Hint: you can do the following

    <img border="0" src="/path_to_file/group$GROUP_ID$.gif">

    And display in such a way the necessary image for each group.

    There is a link to the help on conditional operators in the Control Panel, there you can find out what conditional blocks mean and can see the examples.

    Posts: 43
    Reputation: 1
    Message # 3 | 1:15 PM
    Hello! My question in some Traductors:

    Traduction by Google Traductor:

    Hello, I'm now talk in Spanish:

    My doubt is: can not be done so that users and unregistered them see one thing differently than managers or moderators?
    I entered the code:

    <? if ($ USER_LOGGED_IN $)> Hello USER $ $! <? if ($ group_id = $ 3 | | $ group_id = $ 4)?> Do not forget to click on the ads! <? endif> <? else?> Please, register. <? endif>

    But it is not clear is what Hello USER to the groups mentioned in: $ group_id = $ 3 | | $ $ group_id = 4

    That is what I want, is a code that makes the registered and unregistered show them what I want and groups that I want to show him other things .... I do not know if I explain.

    Sorry for not speaking in English, but that this problem is that I would have little difficult to explain.

    Thank you. Victor.

    Traduction by babelfish:

    Hello, I' m talk now in Spanish: My doubt is: it is not possible to be done so that the registered users and to a thing different that from the administrators or moderators is not seen them? I have introduced the code: Hello $USER$! Don't forget to click on the ads! Please, to register. But it is not clear, sees the one of Hello USER the groups mentioned in: $GROUP_ID$=3 || $GROUP_ID$=4 That is to say, what I want, it is a code that does that the registered registered ones and to it is not to them what I want and to the groups that I want she shows other things to him…. I do not know if I explain myself. You pardon not to speak in English, but it is that this problem that I have me haria a little difficult to explain it. Thanks. Victor.

    I'm here for help you!
    Posts: 117
    Reputation: 52
    Message # 4 | 1:56 PM
    <?if($USER_LOGGED_IN$)>Hello USER!
    <?if($GROUP_ID$!=3 && $GROUP_ID$!=4)?>Do not forget to click on the ads!<?endif?>
    <?else?>Please, register.<?endif?>
    Posts: 10
    Reputation: -4
    Message # 5 | 4:16 PM
    ($USER_LOGGED_IN$) is true and false

    i mean

    i am in visual html editor and i want to change the IF conditions to ($USER_LOGGED_IN$) true to fase because i am writting login and i dont want to show it when user is register so how can i change the IF conditions from true to false

    i am not saying about normal conditions i am saying about IF conditions i want to change to false

    Added (2008-08-19, 10:16 Am)
    can anyone help me

    thank you

    have a good day

    Posts: 117
    Reputation: 52
    Message # 6 | 1:40 PM
    thapchi, read condition help!

    <?if($USER_LOGGED_IN$)?> - TRUE
    <?if(!$USER_LOGGED_IN$)?> - FALSE

    Posts: 9296
    Reputation: 456
    Message # 7 | 10:48 AM
    If I got you right then

    Quote (Sunny)
    Nesting of operators is supported

    I'm not active on the forum anymore. Please contact other forum staff.
    Posts: 1
    Reputation: -1
    Message # 8 | 7:27 PM
    Hi there, please PM me the answer Sunny!,

    I am making a VIP Service in my site

    like normal Users And VIP

    the VIP Dudes have like VIP Points, that they can earn And Spend

    I Want to make like if that user was VIP,
    then IN his Personal Page There Is VIP Points
    if not i dont want the other groups to see VIP Points in their Own Pages (But they can see the VIP Points in the VIP Users Personal Page)

    How do i do it????/???
    PS: if you can ... tell me how to make the VIP Points Get +1 VIP Point every Time that user Posts a thread.....,,, howww??

    please.. and if you can not.. tell me how to make the VIP Points Editable By Admins like they go to the VIP Users page and edit them

    Please PM ME PM PM PM

    Posts: 111
    Reputation: 0
    Message # 9 | 9:20 PM
    hnakhi, There is no such feature
    Use your brain before you post ~Lee
    Please use search, ~Lee
    Posts: 278
    Reputation: 10
    Message # 10 | 10:42 AM
    DON'T WORK!!!

    <?if($IS_GROUP_4$ and $IS_GROUP_6$)?> <a href="$HOME_PAGE_LINK$/index/0-13">$USER_GROUP$</a><?else?><font color="#dda0dd">$USER_GROUP$</font><?endif?>

    <?if($IS_GROUP_4$='<a style="font-weight: normal; font-style: normal; text-decoration: none; color: rgb(255, 0, 0); letter-spacing: 0pt;" href="$HOME_PAGE_LINK$/index/0-13">Administrators</a>' and $IS_GROUP_6$='<a style="font-weight: normal; font-style: normal; text-decoration: none; color: rgb(255, 255, 255); letter-spacing: 0pt;" href="$HOME_PAGE_LINK$/index/0-13">Īpašnieks</a>')?><?else?>$USER_GROUP$<?endif?>


    <?IF($IS_GROUP_4$)?> <a href="$HOME_PAGE_LINK$/index/0-13">$USER_GROUP$</a><?ELSE?> <font color="#dda0dd">$USER_GROUP$</font> <?ENDIF?>


    Support forum
    Post edited by jackass - Sunday, 2008-03-23, 2:09 PM
    Posts: 9
    Reputation: 7
    Message # 11 | 10:43 AM
    jackass, because of
    Quote (jackass)
    $IS_GROUP_4$ and $IS_GROUP_6$

    User cannot be in 2 groups at the same time. happy Right code :
    <?if($GROUP_ID$="4" || $GROUP_ID$="6")?><a href="/index/0-13">$USER_GROUP$</a><?else?><font color="#dda0dd">$USER_GROUP$</font><?endif?>


    I'm from Russia, sorry for my english.
    If I helped you give me a respect.
    Posts: 1
    Reputation: 0
    Message # 12 | 8:51 AM
    Hello colleagues,
    Could you please advise how to hide mini-chat from unregistered users using conditional operators? I did the following (but it didn't work):
    <div class="cBlock$PARITY$" style="padding:0 4px 5px 2px;margin-bottom:3px;">
    <Mini-chat template goes here>

    As a result, nobody can see the mini-chat, incl. registered ones. After removal of the first and last row - everybody can see wacko

    Post edited by virtuoso - Tuesday, 2009-08-04, 11:59 AM
    Posts: 93
    Reputation: 18
    Message # 13 | 1:39 AM
    Can I use conditional operators in my entries html?

    For example:
    I will create a new post in my blog, I have to put a post name, a brief description and the text, ok?? ok!!

    So, in the text field I'll put 2 videos, but I want the first can be viwed by guests and registered users and the second video just by registered users.

    This can be done?

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

    Time is the most valuable thing a man can spend.

    Posts: 1424
    Message # 14 | 11:05 AM
    virtuoso, user group permissions.

    Quote (Igor-Sousa)
    This can be done?
    You go and test it.
    Posts: 93
    Reputation: 18
    Message # 15 | 0:53 AM
    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.

    uCoz Community » uCoz Modules » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
    Page 1 of 151231415»