uCoz Community uCoz Modules Additional Features Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>) |
Conditional Operators |
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 Now we have just to close it. 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: Days after registration: 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. <?if($USER$='Mike' or $USER$='Lola')?> Mike and Lola, here is a secret link …. <?endif?> Groups: 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: I'm not active on the forum anymore. Please contact other forum staff.
|
And If I change the online games to file catalog? That User needs to make 5 Posts before downloading any thing?
Added (2011-01-22, 6:37 Am) |
Quote (SirDarknight) And If I change the online games to file catalog? That User needs to make 5 Posts before downloading any thing? just use conditional operators like you did before but just put the codes of file catalog in it
Quote (SirDarknight) When I used Ctrl+F to search for $CALENDAR$ It says item not found is normally located in blocks look if you have 2 $CALENDAR$ codes there or not , also if there is only 1 code in blocks search on other places (templates) for a second code , i'm not god i can't guess where you used the $CALENDAR$ code twice To busy building a passive income online ;)
|
Code <?if(!$USER_LOGGED_IN$)?><script><a href="javascript://" onclick="new _uWnd('myName','Welcome',500,200,{min:1,shadow:1,header:1,max:1,resize:0},'Guests are not able to download anything and viewing some forums. <a href="http://www.hugesoft.tk/index/3">Register Here</a> and Download Anything ');"></a></script><?endif?> Why It doesn't work? I want when Guests will access a pop up will appear and tell some text. Added (2011-01-29, 2:52 Am) Code <?if(!$USER_LOGGED_IN$)?><script> new _uWnd.alert('Guests are not able to download anything and viewing some forums. <a href="http://www.hugesoft.tk/index/3">Register Here</a> and Download Anything ','Welcome',{w:500,h:100,tm:30000}); But I want the Minimize and Maximize Button. Added (2011-01-29, 2:54 Am) Quote (Sunny) Days after registration: <?if($USER_LOGGED_IN$)?> You are with us for $USER_REG_DAYS$ days! <?else?> Please, register. <?endif?> What Does It mean? |
I like the codes given in the 1st thread of this post related to Hello username or else Hello guest, please register.
I want to know where do I put the codes in my website? If I have to put it in between <head> and </head> then which part of <head> should I add the code to? Please guide me on this matter, I log in to my control panel and then click on design > design management (templates) and I find parts of the template broken down into global blocks, page editor and the modules installed....... now in which part of the template code do I add the code for user's welcome message? |
Is there a link to a list of ALL the operators?
I'm trying to make it so if an admin is online, text will say so. I thought I had to by doing <?if($USERNAME$=='OwnerTravis')?>online<?else>offline<?endif?> It appeared to work, but quickly I realized that only I could see it. (my username is OwnerTravis) I'm sure I could figure it out if I knew all the operators available, however I don't know them. I'm sure there is a simple one like $ADMIN_LOGGED_ON$ or something that would make it obvious on how to make this command. Any help/suggestions are appreciated, thank you. Added (2011-02-23, 5:44 PM) Post edited by Lt99range - Wednesday, 2011-02-23, 11:03 PM
|
Lt99range, if I got your problem correctly, you want to show something the admins am i right? For that you can try the code below.
Quote <?if($GROUP_ID$==GROUPID)?>Some Admin Stuff<?endif?> GROUPID is the corresponding ID column found on http://mon3y.ucoz.com/panel/?a=users;l=groups. If that's not what you're aiming for, feel free to give more information about what you want to achieve. "Friends don't let friends use Internet Explorer 6." - Microsoft || Join the cause. Help your friends.
|
shadowslash, No. I knew how to do that, what I want is when an admin is online, a message says "An admin is online", and if there aren't, it says "all admins are offline"
Basically this LOGIC: <?if($A_ADMIN_IS_ONLINE)?>An admin is online!<?else?>No admins are online.<?endif?> Added (2011-02-23, 8:04 PM) If it helps currently I am the only admin, and probably will only ever be the only admin lol. Its so users know there is a admin currently available. Post edited by Lt99range - Thursday, 2011-02-24, 2:09 AM
|
Lt99range, sorry for the late response, I had to cook up the code from scratch but anyway, here you go. It may not be the direct solution to your question but it does let you detect if a user is online or not.
Here's my new tutorial in the Hints and Tips for uCoz section. "Friends don't let friends use Internet Explorer 6." - Microsoft || Join the cause. Help your friends.
|
The first post is confusing.. What code do I need if I want guests to see this text:
"Welcome to TheHelperUnion! As a guest, you cannot view most of our pages. To be able to see our great guides, register using your HorseIsle 2 Username!" And for everyone to see other text, including guests? |
HorseIsleSense,
Code <?if($USER_LOGGED_IN$)?>Users logged in see this so change this<?else?>Welcome to TheHelperUnion! As a guest, you cannot view most of our pages. To be able to see our great guides, register using your HorseIsle 2 Username!<?endif?> |
Conditional code being used in news posts isn't functioning correctly. The code on its own works fine but when I add it to the html source for the news entry it fails
Code <?if($USER_LOGGED_IN$)?> <div style="text-align: center;"><span style="font-size: 14pt; ">Download Here</span><div><a href="http://www.webserver.com/file.exe"><img src="http://www.webserver.com/image.jpg"></a></div><?else?><div align="center">Sign up now to download this file!</div><?endif?> </div> The code is designed to only allow user how are logged in to download the file. Does the if statement just not work in news entries?? |
| |||