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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.