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.
|
Has uCoz the <?if?> code for IE? I mean, the information will be visible for user, which enters my site with IE.
|
Quote (Sunny) shengelia, explore the available codes, you need the code $USER_AGENT$ And can I use something like this <?if($USER_AGENT$=$IE$)?>something<?endif?> |
Can I use something like <?if($GROUP_ID$=4$)?> for Category Id?
|
no it has to end with <?endif?> <?else?> is by means if something doesn't apply to the pre written text, it will affect them. such as
Code <?if($USER_GROUP$)='Admin'?>Read the pm I sent you<?endif?> Web design and film == my 2 passions.
Genesis Inc. ~ New Horizons, New Beginnings Post edited by NTP - Friday, 2010-01-15, 2:17 AM
|
Hey, sorry but ive tried as much ways as I can think of and I realy need this code.
Im using my own custom design, and I realy need Section ID Operators for the design. Is there any way I can use conditional operators for different sections in a module (for example: Publisher). This is an example of what I mean: Anyway, what I mean is, I have a head menu which highlights the active page. I know hwo to make each link active, but I cant spread each section without a conditional operator. The screenshot below should explain better: If you know the conditonal operator for different section ids in the module, please help Also the $PAGE_ID$ doesnt seem to be working.
Attachments:
6393095.png
(20.2 Kb)
Kind regards,
Elliott. "The best uCoz" critic since 2007. Qualified website, branding, print & user interface designer. I'm on Behance and Twitter. Post edited by Mistory - Sunday, 2010-01-31, 12:49 PM
|
Thanks for response Sunny, il give it ago.
Added (2010-02-04, 5:57 Pm) Please help |
Im using the code exactly how it is displayed in the Conditional Operators example in Custoize Design -> Site Pages (and thats were im trying to use)
My main page is called exactly 'Homepage'. But neither is working. Ivs also tried: <?if($PAGE_ID$='1')?> but nothing Added (2010-02-08, 1:07 Am) Kind regards,
Elliott. "The best uCoz" critic since 2007. Qualified website, branding, print & user interface designer. I'm on Behance and Twitter. Post edited by Mistory - Friday, 2010-02-05, 2:26 PM
|
No matter, kostova shown me. I guess Dartz may of deleted the post
This is the code kostova had given me and it works: <?if($PAGE_ID$='sitePage1')?> Thanks anyway Sunny
Edited: Kind regards,
Elliott. "The best uCoz" critic since 2007. Qualified website, branding, print & user interface designer. I'm on Behance and Twitter. Post edited by Mistory - Tuesday, 2010-02-09, 4:03 PM
|
| |||