Context Rules
From bemoko developer wiki
What are context rules?
Context rules allow a site development to define rules which can be triggered from a URL request to change how the context is resolved. For example this allows you to define a keyword such as "320", which when included in the URL, will force the rendering of the site to be what would be delivered to a 320px device.
How do I enabled context rules?
In your site-config.xml include configuration as follows:
<context> <rules> <rule name="iphone"> <param action="replace" name="user-agent">Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16</param> </rule> <rule name="320"> <param action="replace" name="user-agent">Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413 es61i</param> </rule> </rules> </context>
If you include these rules in a site called test' with an intent called i, then you can activate the iphone rule by including the iphone rule in the URL as follows:
Notice that the iphone rule is included in the URL after the site name and before the intent name.
Overlaying a new UI via a context rule
Perhaps you want to deliver a slight variation of the content to a browser embedded in an app as opposed to a user connecting with the native browser. This allows you to embed web content in a native app wrapper, e.g.
<context> <rules> <rule name="app"> <!-- if app context rule is specified in URL then trigger the "app" UI --> <param action="ui">app</param> </rule> </rules> </context> <uigroup> <!-- define the "app" UI as disabled by disabled by default, with it only getting enabled if the context rule triggers it --> <ui name="app" expr="false"/> </uigroup>
means that when a user connect with
resources will be picked from the "app" UI before the before the default UI fallback path, which allows you to customise certain elements of the page. e.g. don't deliver header and footer, because native app is delivering those parts of the UI.
Advanced Usage
Essentially the context rule allows you to trigger alternative HTTP headers by providing URLs to the user with the context rule in. The example above shows you how you can change the user-agent HTTP header - the user-agent is the primary mechanism by which a device identifies itself.
You could however control other parameters, for example to emulate a request from a blackberry without CSS enabled you can include the following rule
<rule name="bb8310-nocss"> <param action="replace" name="user-agent">BlackBerry8330/4.5.0.66 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1</param> <param action="replace" name="accept">text/html</param> </rule>
Version History
This feature is available from v1.2.5 of bemokoLive.
