We are proud to announce our latest innovation to the Verb hosted CMS platform: VerbQL. VerbQL stands for Verb Query Language and it is a new layer in the stack that handles the verb() PHP function and paths provided to VerbML tags via the path="" attribute.
VerbQL adds the ability to perform math operations, comparisons, if statements, variables, and PHP functions directly in your path="" attributes and any other place a path is used in Verb. There's a lot here, so we'll break it down with some examples.
1. Beef up your <v:if> statements.
Previously, you could only test for the existence of a field within a <v:if> statement. You can now perform any kind of test, and you may also group tests together. Let's start with a simple comparison. This would test if the price structure is greater than 5:
<v:if path="price>5">
Yep, that's now valid VerbML. <, <=, and >= also work. You can also test equality and inequality:
<v:if path="name=='Kevin'">
<v:if path="name!='Kevin'">
You may also use a single equal sign for equality and the <> operator for inequality. Whatever you prefer. Now, let's get fancy:
<v:if path="(price+5)</home/featured_price">
This item is more than $5 less than the featured item price!
</v:if>
The math operators +, and - work as expected for add and subtract. Multiplication and division are also supported, though their operators are doubled: ** and //. This is to prevent confusion, as otherwise, we wouldn't know if artist/123 meant the artist with ID 123, or the value of artist divided by 123.
What if you wanted to test if the price is an even number? Do this:
<v:if path="!(price%2)">
The % operator is the modulus operator, which represents the remainder from performing an integer division. In our example, this will be 0 for even numbers. We add the not operator (the exclamation mark) to take the reverse of this -- return true when the modulus is 0, and false otherwise.
You can also check for multiple conditions:
<v:if path="featured&&digital">This is a featured digital product</v:if>
&& is the symbol for and, || is the symbol for or. You can also use the words 'and' and 'or' directly. This would be the same thing as above:
<v:if path="featured and digital">This is a featured digital
product</v:if>
2. Adding conditional statements to other VerbML tags
VerbQL also supports the "inline-if" statement popular in many programming langauges. It works like this:
<v:text path="featured ? featured_description : description" />
If the path featured evaluates to true (it's a checked checkbox or a text field with text in it, etc.), then we will display the featured_description. Otherwise, just the regular description.
Combine this with the above, and we can make some pretty awesome statements:
<v:text path="(price>=100 and featured) ? 'SUPER VALUE!' : 'Good Value')" />
Note that you can use request variables within VerbQL as well:
<v:text path="($from == 'wholesale' ? wholesale_description : description)" />
Note that in VerbQL, variables correspond to the request variables sent to the page either via a POST or in the URL. This corresponds (and is linked into) the $_REQUEST array in PHP.
3. Built-in support for PHP Functions
Verb paths have always supported some functions such as now() and host(). These were built-in functions, and there were only a few available. Now VerbQL supports the entire PHP function library, and you can even define your own functions in PHP and use them in VerbML. All the old functions are there too.
Here are some examples:
<v:text path="substr(description, 10, 10)" />
<v:collection path="items[price<PRICECUTOFF()]">
Functions can take arguments, which can be paths, variables, functions, or a full VerbQL query in its own right.
VerbQL also supports "range queries", which will let you specify a range for values. Use a colon and a function within a predicate. This would search for items with prices between $10 and $50:
// in __verb.php:
function PRICERANGE() {
return array(10, 50);
}<v:collection path="items[price:PRICERANGE()]">
4. Go crazy!
All of these things can be combined and used in all sorts of ways. Play with it and figure out what works best for your applications.
VerbQL is immediately available on all Verb sites. As always, thanks for using VerbCMS!