Username Password
Bookmark and Share

If Macro


N.B. In 7.6.0 the old ^If(); Macro was removed from WebGUI. In 7.6.4 a new macro was introduced, which tests whether a given string is non-empty or not. This new macro is confusingly also called ^If();, so if you upgrade from <7.6.0 to >=7.6.4 and use ^If(); on your site, you're in for a big surprise. None of the examples below work with the new ^If();, which considers all of the given conditions to be always true, because they all contain a non-empty string.


A simple conditional statement (IF/THEN/ELSE) to control layout and messages.

Display Happy New Year on 1st January: ^If('^D("%m%d");' eq '0101' , Happy New Year);

Display a message to people on your subnet (192.168.1.*):
^If('^Env("REMOTE_ADDR");' =~ /^192.168.1/,"Hi co-worker","Hi Stranger");

Display a message to Windows users:
^If('^URLEncode("^Env("HTTP_USER_AGENT");");' =~ /windows/i,"Hey... Linux is free !");

Display a message if a user is behind a proxy:
^If('^Env("HTTP_VIA");' ne "", You're behind a proxy !, Proxy-free is the best...);

Display Good Morning/Afternoon/Evening:
^If(^D("%J");<=12,Good Morning,^If(^D("%J");<=18,Good Afternoon,Good evening););

Keywords: if macro

Search | Most Popular | Recent Changes | Wiki Home
© 2022 Plain Black Corporation | All Rights Reserved