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.
  • Blazer
    Posts: 310
    Reputation: 25

    Message # 121 | 6:11 PM
    Helpinghand,
    The code below will display " Hi, Guest WELCOME TO FREE DOWNLOAD FOR ALL - WWW.FREEFORALL.UCOZ.COM " for guests ( place the code where you want the text to appear ), i hope this is what you wanted

    Code
    <?if(!$USER_LOGGED_IN$)?><?if($USER_LOGGED_IN$)?>Hi, Guest WELCOME TO FREE DOWNLOAD FOR ALL - WWW.FREEFORALL.UCOZ.COM<?endif?>


    To change the text change the green text

    If i helped you + My Reputation and Give me an Award.
    Post edited by Blazer - Monday, 2011-06-27, 6:14 PM
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 122 | 6:09 AM
    Blazer,thanks, but im confuse can u tell me detail..where i put this,pls.
    Natashko
    Posts: 3366
    Reputation: 171

    Message # 123 | 8:53 AM
    Helpinghand, go to CP->Design->Design management (templates)->Top part of the website->substitute your whole code there with this one:

    "SOME TEXT" part should be substituted with your own phrases.
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 124 | 5:36 PM
    Natashko,thanks for your suggetion,but,After paste it only show im write anything,but im post my forum link,when click here page directly go forum section. Can i post one video,exatly what im doing.
    Post edited by Helpinghand - Tuesday, 2011-06-28, 5:38 PM
    Natashko
    Posts: 3366
    Reputation: 171

    Message # 125 | 9:23 AM
    Helpinghand, substitute SOME TEXT with
    Code
    <a href="/forum">Go to forum</a>
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 126 | 5:06 PM
    Natashko,im not succes to create this(Conditional operators),pls help.......
    Paste Your provide full code(same):

    But,not same,Visit my site:
    http://freeforall.ucoz.com/
    Pls visit the the site:

    Im try to make same (Conditional operators)logo.
    Pls......Help me.
    Animorph
    Posts: 2856
    Reputation: 189

    Message # 127 | 5:40 PM
    Helpinghand, I don't see how the logo of http://www.freedl4all.net/ is connected to yours , that website has alot of conditional operators under the logo and 1 in the logo itself , he has it when you enter the forum the logo is different but thats all. please be more specific about what you want
    To busy building a passive income online ;)
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 128 | 2:13 PM
    Animorph,thanks for your replay,Im trying to make,This type Available for users only
    ,Actually im create this"Conditional operators"top of my site,Below my site banner.When click this"Conditional operators link"Redirect page automaticaly site forum.But this"Conditional operators link"hide in forum section.
    Animorph
    Posts: 2856
    Reputation: 189

    Message # 129 | 9:24 AM
    Helpinghand, Oh thats easy smile

    1.Welcome text with conditional operators.
    Code
    HI <?if($USERNAME$)?>$USERNAME$<?else?>guest<?endif?> WELCOME TO FREE DOWNLOAD FOR ALL - www.websitename.com


    2.Link to forum
    Code
    <a href="url" >Free Premium Account Filesonic, Hotfile , Fileserve , Rapidshare ,Depositfiles , And Many More... Visit Here</a>

    To busy building a passive income online ;)
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 130 | 4:02 PM
    Animorph,Thanks...really working for me.

    Added (2011-07-26, 10:02 Am)
    ---------------------------------------------
    Animorph,But still one problem..im trying to make all "Free Premium Account Filesonic, Hotfile , Fileserve , Rapidshare ,Depositfiles , And Many More... Visit Here"just one line & centre & put "red"color,but im not success.

    Animorph
    Posts: 2856
    Reputation: 189

    Message # 131 | 10:18 AM
    Helpinghand, to center and color it red you can use
    Code
    <div align="center"><font color="red">your code</font></div>
    to make it in one line hmm it depends on the width of your site design.

    To busy building a passive income online ;)
    Helpinghand
    Posts: 37
    Reputation: 0

    Message # 132 | 7:03 PM
    Animorph,thanks......really helpfull site.

    Added (2011-07-28, 1:03 PM)
    ---------------------------------------------
    Animorph, Can u tell me how to create a banner & how to atach in my site(What is the exatual size of ucoz site banner)im confuse,any special software need create banner.

    Animorph
    Posts: 2856
    Reputation: 189

    Message # 133 | 0:54 AM
    Helpinghand, I don't see how this is related to this thread, you can create a banner with photoshop or any other graphic software program.
    To busy building a passive income online ;)
    khen
    Posts: 475
    Reputation: 13

    Message # 134 | 4:39 PM
    Are there any negative effects to a web page if we put over a thousand conditional operators on it? What are these?
    Post edited by khen - Saturday, 2011-08-06, 2:19 AM
    coatham
    Posts: 248
    Reputation: 9

    Message # 135 | 3:08 PM
    Is there a IF function if so where is it because i want to create a dropdown menu that can change text on a page
    Need More In Depth Help About a topic post it here: Click Here
    uCoz Community » uCoz Modules » Additional Features » Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>)
    Search: