|
You are here: Home / Documentation / XT Expressions |
XT ExpressionsPHPPHP code in expressions has a different syntax and a few caveats compared to straight-up PHP code in a script. For one, in Sitellite objects are the way we manipulate data and also often contain the logic needed to manipulate themselves, so the PHP code in XTE expressions can't shy away from objects. The problem is, PHP's object syntax is not very conducive to working within an XML tag attribute. You see, the > character in $site->url or any other property or method reference would have to be written as >, which is the XML entity used for displaying > characters, since the > character has special meaning in XML (the closing of a tag). So what XTE allows you to do is to refer to objects like this: site.url This will be translated into $site->url just before being evaluated. You can also get away with doing this with arrays, for example: people[joe] XTE simplifies this in two ways: First it adds the missing dollar sign before people so you have $people[joe], and second it quotes joe so you have $people['joe'], which is correct PHP-speak. But don't worry, XTE can be told not to quote values you mean to be variable, for example: people[ cgi.person ] This will be turned into $people[$cgi->person] like you'd expect. Just make sure you include the space between the square braces and the object inside of them. Actually, XTE goes a step further with objects and arrays in inline PHP expressions. You see, so that calls to XTE do not modify values outside of itself (ie. if a variable is set in XTE it does not exist outside of XTE, and if a variable taken from outside XTE is modified, the modification only affects the copy that XTE took of it and not the real thing). This is because XTE keeps its own register of objects and arrays. This is where the main caveat with using PHP in XTE expressions comes in. site.url doesn't actually call $site->url or even $GLOBALS['site']->url. It calls $this->register['site']->url. This means that objects called in PHP expressions must first be registered by XTE. Paths do this for you automatically, but PHP expressions do not due to the way they are evaluated. This is why there is an <xt:register> XT tag, which registers a global object with XTE without using it yet. Page 1: The real power behind the XT tem... |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |