How can I get part of the $userAgent variable

AndyB

Well-known member
I would like to see if the $session.userAgent variable contains the word "iPad".

Currently I have the following code in the PAGE_CONTAINER template and it works fine:

Code:
<xen:if is="{$session.userAgent} == 'Mozilla/5.0 (iPad; CPU OS 7_0_3 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B511 Safari/9537.53'">  
<xen:comment>ipad</xen:comment>
<xen:else />
<xen:include template="page_container_js_head" />
</xen:if>

How would I use xen:string or xen:helper or any other command to get part of the $session.userAgent variable?

Thank you.
 
Last edited:
AFAIK you can't do this inside the template

A possible solution would be to validate this on event visitor_setup and attach your informations to the visitor object!
Then you could use if is="{$visitor.isIpad}">...</ inside the templates.
 
Last edited:
I got it! This works perfectly.

Code:
<xen:if is="{xen:helper wordtrim, $session.userAgent, 20, 'iPad'} == 'Mozilla/5.0 (iPad;...'">  
<xen:comment>iPad</xen:comment>
<xen:else />
<xen:include template="page_container_js_head" />
</xen:if>
 
Top Bottom