uCoz Community » uCoz Modules » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
Conditional Operators
Sunny
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?>

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 active on the forum anymore. Please contact other forum staff.
  • Paradox
    Old Guard
    Posts: 3284
    Reputation: 145

    Message # 136 | 3:18 PM
    coatham, if you are meaning as in the ucoz conditional operators some of them are enabled on the page editor module but they are not listed. If you are meaning otherwise could you please be more specific. smile

    Hope this helps, happy

    Jack of all trades in development, design, strategy.
    Working as a Support Engineer.
    Been here for 13 years and counting.
    coatham
    Posts: 248
    Reputation: 9

    Message # 137 | 3:30 PM
    Nah thats it! but where do i find it?
    Need More In Depth Help About a topic post it here: Click Here
    Paradox
    Old Guard
    Posts: 3284
    Reputation: 145

    Message # 138 | 4:01 PM
    <?if(condition)?><?else?><?endif?>

    They look just like the normal ones in the design customisation settings. smile The only twist is that only a limited number of them are enabled from what I've experienced. wink

    Jack of all trades in development, design, strategy.
    Working as a Support Engineer.
    Been here for 13 years and counting.
    Natashko
    Posts: 3366
    Reputation: 171

    Message # 139 | 10:43 AM
    khen, I assume that all the conditional operators generate the page code. The more conditional operators you have - the longer time is required to generate the page code. If their number is over 1000 - it might cause the delay in the loading of the page.
    khen
    Posts: 475
    Reputation: 13

    Message # 140 | 5:10 PM
    Is it possible to create a 1 complete word from a phrase of words using Conditional Operators? To clarify, I'll give an example:

    I want to create a 1 complete word from the Entry Title "Are you going to answer this?". Given that this is the entry title posted by the user and I don't know that this is the entry title he created. What I want is to just randomly create 1 complete word from the "Are you going to answer this?

    Natashko
    Posts: 3366
    Reputation: 171

    Message # 141 | 10:51 AM
    khen,
    Quote (khen)
    Is it possible to create a 1 complete word from a phrase of words using Conditional Operators? To clarify, I'll give an example:

    Unfortunately, I can not understand you at all. Please explain better.
    Zevoxa
    Posts: 237
    Reputation: 4

    Message # 142 | 10:21 PM
    How would I make admins and moderators a certain color in forum, File cata., etc.?
    I would prefer if you called me ErraticFox. ^_^
    redhead
    Posts: 113
    Reputation: 9

    Message # 143 | 11:23 AM
    Poptart, This link might be helpful http://forum.ucoz.com/forum/9-13738-78964-16-1309160490
    vasil7112
    Posts: 9
    Reputation: 0

    Message # 144 | 5:54 PM
    And if i would wanted a Container be visible for Guest,Users,Checked and not to vips,admins e.t.c then how do i do it?

    Please give me an example code!
    Post edited by vasil7112 - Wednesday, 2011-10-26, 5:55 PM
    DEEPKG
    Posts: 316
    Reputation: 8

    Message # 145 | 7:36 PM
    vasil7112,

    working for all users including admin

    Code
    <?if($USER_LOGGED_IN$)?>your content code <?else?>no content <?endif?>


    For Some group

    Code
    <?if($GROUP_ID$!='1' or $GROUP_ID$!='2' )?>your content code <?else?>no content <?endif?>


    hope this help smile

    hit rep+ If this help's

    I Try to help. U can Try to give Rep ++ For my try :P
    Post edited by DEEPKG - Wednesday, 2011-10-26, 7:37 PM
    vasil7112
    Posts: 9
    Reputation: 0

    Message # 146 | 7:47 PM
    Quote (DEEPKG)
    vasil7112,

    working for all users including admin

    Code
    <?if($USER_LOGGED_IN$)?>your content code <?else?>no content <?endif?>

    For Some group

    Code
    <?if($GROUP_ID$!='1' or $GROUP_ID$!='2' )?>your content code <?else?>no content <?endif?>

    hope this help smile

    hit rep+ If this help's


    Thanks!
    Found another way!(Easyer)
    1)Open the website
    2)Login
    3)Builder
    4)Click the gear
    5)Finished(After edititng;)
    DEEPKG
    Posts: 316
    Reputation: 8

    Message # 147 | 2:44 AM
    vasil7112, That Nice but above Code cqan be use other then sidebar Anyways congrats biggrin
    I Try to help. U can Try to give Rep ++ For my try :P
    Gest3r
    Posts: 16
    Reputation: 0

    Message # 148 | 10:24 PM
    Is there a code that would fit into 'it has been viewed' ?
    <?if(it has been viewed)?> This blog has been readed<?else?> Not readed <?endif?>

    I need to put this into my Informer and i can't find anything releated to this
    Zevoxa
    Posts: 237
    Reputation: 4

    Message # 149 | 11:14 PM
    Gest3r, I don't think this has been implemented, but it seems like a good idea happy
    I would prefer if you called me ErraticFox. ^_^
    Post edited by Poptart - Tuesday, 2011-11-08, 11:20 PM
    Gest3r
    Posts: 16
    Reputation: 0

    Message # 150 | 10:55 AM
    I would be great if uCoz had one of theese options.

    Also i am having problems with $ID$, $UID, $CID$.

    I have no idea what each of thoose do. I need a code that shows blog post order in specific category not whole blog.

    For example: When i try to use $ID$ in Informer - i get number 80. If i am right then its the number of my last 'whole blog' post. I need code that will order posts that are only in my specific category.

    Added (2011-11-09, 4:55 Am)
    ---------------------------------------------
    Another thing that i need:
    <?if(current date > date the News were published)?> News are old <?else?> News are fresh <?endif?>

    Is there anything like this?

    uCoz Community » uCoz Modules » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
    Search: