We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Detecting touch devices for responsive design

Development and Programming

giusi's avatar
giusi
94 posts
14 years ago
giusi's avatar giusi

Hi

I have recently looked for plugins(is iphone, mobile detector, etc.) that detect touch devices (iphone, ipad, android handsets); these plugins share the following code:

function Is_Iphone()
  {
        $ua = $_SERVER['HTTP_USER_AGENT'];
        if (strpos($ua, 'iPhone') !== FALSE){
                $this->EE =& get_instance(); 
            }
        
        $this->return_data .= $this->EE->TMPL->tagdata;
  }

I would like to extend one of these plugin to cover more devices, but I don’t like that i would end with templates that look like this

{exp:is_touch:iphone}
code…
{/exp:is_touch:iphone}
{exp:is_touch:ipad}
code…
{/exp:is_touch:ipad}

I would prefer something like this:

{exp:is_touch}
{if iphone}
code…
{/if}
{if tablet}
code…
{/if}
{/exp:is_touch}

I have read through the documentation but I have some difficulties putting things together, it’s my understanding the way conditional variables should be coded is:

function devices()
    {
        
        if (trim($tagdata) !== '') {
            
            $variables = array(
                'is_iphone' => 'FALSE',
                'is_ipod' => 'FALSE',
                'is_android => 'FALSE'
            );
            
                $this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, array($variables));
        }
        
    }

but I have come to the conclusion I haven’t really understood the syntax because all my tests fail 😊 Adding $variables[‘is_iphone’] = 1; to the is_iphone function then trying to evaluate {if is_iphone}code…{/if} didn’t worked.

I am sure I am not understanding the correct process, but I can’t find examples of similar plugins that use conditionals to improve my knowledge. Any ideas/suggestions/references ?

Thanks in advance

EDIT: what i would like to accomplish is removing content if not needed (on a mobile version of a website I could remove an author image or a post excepert and showing titles only), serving smaller images to mobile devices or alternative navigational systems, and in general all the sort of problems media queries can’t solve.

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Try this:

function devices()
{

  if (trim($tagdata) !== '') 
  {

    $variables = array(
      'is_iphone'     => FALSE,
      'is_ipod'         => FALSE,
      'is_android'    => FALSE,
    );

    $this->return_data = $this->EE->functions->prep_conditionals($this->EE->TMPL->tagdata, $variables);

  }

}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.