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.
|
hi guys, I have a little trouble
ex: I have 2 cataloge A and B. A have 10 posts (A1, A2, A3 .....A10) and B have 15 posts(B1, B2, B3..... B15) . I want to create inform. when access B1, or B2 the inform will show related post in only cataloge B, When when access A1, or A2 the inform will show related post in only cataloge A. I try any way but all fail. Can anyone help me? thanks. |
MMM5264, by standard means it is not possible. May be possible with custom scripts, but if you have a lot of entries, there is a risk of IP blocking due to too many requests.
I'm not active on the forum anymore. Please contact other forum staff.
|
How to hide some things from some modules with this. I have try with most codes and it wont work. I want to hide chat box for certain module. !
Huh i resloved with this <?if($MODULE_ID$="dir")?>No code <?else?> code<?endif?> !
Post edited by Ed05 - Friday, 2014-07-18, 2:41 PM
|
If a conditional operator is used :
Code <?if($URI_ID$='page200')?> <title>name</title> <meta name="description" content="about name" /> <meta name="keywords" content="name, about, about name" /> <?endif?> Then the general code that was applied to all "site pages" : Code <title>$SITE_NAME$ - $MODULE_NAME$</title> Must be removed and then you need a conditional operator for every single page ? Otherwise the first version will overwrite the conditional operator. Wouldn't it be better if i could use a single title / meta-description / meta-keywords to automatically produce the page information without writing conditional operators for every single page ? For the title i have this : Code <title>$SITE_NAME$ - $MODULE_NAME$</title> How to write a Meta description and meta-keywords that automatically adjusts like the title depending on page ? Is it possible ? <?$META_DESCRIPTION$?> Thassos Island Portal :
https://thassos.one Post edited by Urs - Friday, 2014-08-08, 5:07 PM
|
It is not necessary to remove the default code for title. In your example, if it is page200 - its specific title/meta tags will be displayed, if it is any other page - the default title will be displayed. In other words, the default title will be displayed on all pages where their specific titles are not set. The default title will not overwrite your conditions. How to write a Meta description and meta-keywords that automatically adjusts like the title depending on page ? Is it possible ? It is possible in content modules - you can use additional fields for meta tags, and then use them in the code, e.g. Code <meta name="description" content="$OTHER1$" /> <meta name="keywords" content="$OTHER2$" /> where $OTHER1$, $OTHER2$ are the codes of the additional fields. I'm not active on the forum anymore. Please contact other forum staff.
|
<title>$SITE_NAME$ - $MODULE_NAME$</title> overwrites any conditional operator. (title)
It would have been better if <title>$SITE_NAME$ - $MODULE_NAME$</title> applied to all pages except for the ones that use conditional operators. So that the conditional operator would overwrite <title>$SITE_NAME$ - $MODULE_NAME$</title> and not the other way around. Thassos Island Portal :
https://thassos.one Post edited by Urs - Monday, 2014-08-11, 5:07 PM
|
Hi All,
It seems len function can not be used with <?if condition. For example, Code <?if(len(S)=100)?>A<?else?>B<?endif?> This function does not work though how hard I try. It seems <?if?> condition only work with expression defined by uCoz. Please help to on this case! |
Good, you can use substrings like this:
Code <?if(len($TITLE$)>50)?><?substr($TITLE$,0,50)?>...<?else?>$_SIGNATURE$<?endif?> This code will show a short version of title, if the title's length is more than 50 characters. E.g. for this title: Quote Original title The title of this long article is more than 50 characters, so it'll be shortened. The code will return: Quote Returned title The title of this long article is more than 50 ch... If the title is short, the code returns $TITLE$ without three points at the end (...). Quote Short title hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau sometimes i lurk here |
Hi Sunny and bigblog,
How about this expression? Could you please help to write in code? If len(S) > 164 and len(S) < 166, then substr (S,2,2) endif thank you~~ Added (2014-09-09, 8:42 PM) |
Is there a uCoz conditional that can round numbers?
Example: http://php.net/manual/ro/function.round.php . |
Mar1aN, the int parameter can do it: http://screencast.com/t/InzTItuk . Example:
Code <?int($ORDER_AMOUNT_RAW$)?> I'm not active on the forum anymore. Please contact other forum staff.
|
| |||