We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2369
    • 44 Posts
    I’m really hoping someone can provide some help with this little issue. I need to detect iPhone/iPod/iPad and serve up an alternate chunk. So far this is the code I’ve implemented via snippet:

    <?php
    if(strpos($_SERVER['HTTP_USER_AGENT'],'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'],'iPod') || strpos($_SERVER['HTTP_USER_AGENT'],'iPad')) {
    $videoPlayer = $modx->getChunk('iphone-video');
    // return the results 
    return $videoPlayer;
    } else {
    $videoPlayer = $modx->getChunk('default-video');
    // return the results 
    return $videoPlayer;
    }


    My problem is that regardless of the device the "else" content is getting served. So clearly the user agent isn’t being recognized. Total loss as to why.

    I’m calling the snippet uncached. Should I be using $modx->getUserData() instead? If so, how should I implement this into the above snippet block? I’ve searched high and low and can’t seem to find any relevant info.

    Thanks in advance!
    ?>
      • 3749
      • 24,544 Posts
      That’s definitely the right code. Try calling the snippet cached.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 2369
        • 44 Posts
        Thanks for the quick reply. After hours of aggravation I finally got it working. As it turns out it was a brainless mistake in the chunks. Doh!