The easiest way to start learning about the Programmable Codes is to see a simple example.
Let’s say you want to direct an iPhone user to one URL, while directing an Android user to a completely different one, and if it’s neither an iPhone, nor an Android user you want to redirect to a third URL.
And here comes the Python Expression:
’http://www.yoursite.com/forIphoneUsers.html’ if click.userAgent.find('iPhone') > -1 \
’http://www.yoursite.com/forAndroidUsers.html’ if click.userAgent.find(‘Android’) > -1 \
And the result:
If an iPhone user scans your code, the following URL will be called:
Even in this simple example, there are a few things to note:
The Python Expression always starts with btpy:::
There are 3 objects that contain the Environment Variabels. These are click, redir and the f object (see below: Available Objects). In this example we only use the click object, and read out the device’s user agent by using click.userAgent
Standard Python syntax is used.
You can perform comparison operators. Here we used > -1
You can use conditional expressions. Here we used if and else.
Use the Backslash "\" if you want to split the Python Expression over multiple lines. IMPORTANT: Nothing is allowed after the backslash, not even a white space character.
As you can see, Programmable Codes can be a very powerful tool!
Sure, you could set up a web server and program this rule or feature on your own, but it means exactly that, you or your developer will need to write some piece of software and you need to maintain a web server – all ending up in much higher costs.
With our Programmable Codes you simply define the Python Expression instead of an URL.
That’s it. No developer, no server, no problems.