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.
|
Im interesed how to add special conditition for hot enterises to mark them hot, i mean most viewed .. i try with this
Code <?if($READS$="1000")?><img src="some image " border="0" align="absmiddle" alt="wink" /> "><?endif?> !
Post edited by Ed05 - Sunday, 2013-11-03, 3:02 AM
|
Hi,
I use /stuff module and i want to make something that shows the entries only for the authors ( person who added the entries ). I use the following condition: Code <?if($USERNAME$=$USERNAME$)?> Appeareance of entries <?endif?> But didn't work. Is there any chanse to make something like that? Thanks. |
Muşatinu, try to use this code:
Code <?if($USERNAME$=$USERNAME$)?> Appeareance of entries <?else?><?endif?> or you may group your authors by using $GROUP_ID$ Post edited by khen - Friday, 2014-01-03, 8:30 AM
|
Muşatinu, khen, guys, at the moment you're both comparing only the same string. You need to determine the $VAR$ that specifies the authors username. It is generally $USER$ or something like that. I will have a look at this module and get back to you later today.
Jack of all trades in development, design, strategy.
Working as a Support Engineer. Been here for 13 years and counting. |
Ed05, Go to CP --> Informers --> Create --> Section: File Catalog --> Data Type: Entries --> Sorting Mode: Entry Comments A or D (depends , if you want the most recent comments or the most popular.) --> Numer of entries and Numer of columns
To busy building a passive income online ;)
|
Animorph, no no we miss understood, i need notification list if other users comments on my enteries for all modules or modules blog and file katalog if is posibile , i need that for my custom script wich looks like this
Code <img src="http://supercafe.ucoz.com/raznokoD/adminpanelstrelica.png" border="0" aling="absmiddle" width="13"><a href="some link">Comments on my enteries</a> <br> And when i click on the link the new tab opens with list.. Added (2014-02-04, 10:21 PM) !
|
Ed05, this option is already made by uCoz.
When you add an entry checkmark this: If you do not have this option go to CP ---> YOUR MODULE ---> Module settings ---> Fields of a new entry form --> Notifications about comments Attachments:
4999263.png
(13.1 Kb)
To busy building a passive income online ;)
|
hello
do we have any alternative conditions like : '< ',' >' or '=<' because i need to use this for $add_date$. |
Canada_Job, yes. You can find a detailed description of conditional operators in the Customize Design section: http://screencast.com/t/HFcDO2OZOzf
I'm not active on the forum anymore. Please contact other forum staff.
|
I want to use one module for more things, and when i add enteries that every entry apear on specified place. for example i want to make page for music and page for images in same module and when i add image that image could not show on page wich i specified like music... ?
That goes with <if? operators but i cant find right one !
|
Ed05, why don't you simply use different module categories for music and for images? Depending on what exactly you want to implement, you could also use Informers that will display entries only of a certain category.
I'm not active on the forum anymore. Please contact other forum staff.
|
| |||