How can I excute a logical && and || in a template file?


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin

How can I excute a logical && and || in a template file?Last Modified: Dec 2, 2013, 4:59 pm
If you're trying to write template code and realized that the template code is too simplistic for what you need, no need to worry, it can still be done.

Before you jump into the guide below, see if the template you're using supports scripts, as that will make your life much easier:
http://www.directadmin.com/features.php?id=285

If not, we'll break down the logical operators for && and || in the DA template form.

&&

The equivalent code for

if (A == "1" && B == "1")
{
     //something
}

in DA template form, would be:

|?TRUE=1|
|*if A!="1"|
|?TRUE=0|
|*endif|
|*if B!="1"|
|?TRUE=0|
|*endif|
|*if TRUE="1"|
     //something
|*endif|

which is the same logical equivalent.



||

The equivalent code for

if (A == "1" || B == "1")
{
     //something
}

in DA template form, would be:

|?TRUE=0|
|*if A="1"|
|?TRUE=1|
|*endif|
|*if B="1"|
|?TRUE=1|
|*endif|
|*if TRUE="1"|
     //something
|*endif|

which is the same logical equivalent.




if-then-elseif-then-else
Normal code:

if (A == "1")
{
     //something1
}
elseif (A == "2")
{
     //something2
}
else
{
     //else something
}

would look like the following in template form:

|?HAVE_SOMETHING=no|

|*if A="1"|
|?HAVE_SOMETHING=yes|
//something1
|*endif|

|*if A="2"|
|?HAVE_SOMETHING=yes|
//something2
|*endif|

|*if HAVE_SOMETHING=no|
//else something
|*endif|






Pay special attention to the ! characters in the template comparisons, as well as the initializing values.  They're the key to the logic being correct.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST