title: Using multiple mobile templates for different devices
body: <p>I'm currently using a <a href="https://github.com/serbanghita/Mobile-Detect" rel="nofollow noreferrer">MobileDetect</a> class within a module for certain things (such as adding a "mobile" class to the body for styling etc). I've also been trying to think of ways of loading different templates for mobile, for example for the list view or the product page, <strong>via xml</strong>. </p>
  
  <p>One way I was thinking this could be done is using a helper to set the template. So for example for the list view:</p>
  
  <pre><code>&lt;catalog_category_view&gt;
      &lt;reference name="root"&gt;
          &lt;action method="setTemplate"&gt;
              &lt;template helper="mobiledetect/switchTemplate" /&gt;                  
          &lt;/action&gt;
      &lt;/reference&gt;
  &lt;/catalog_category_view&gt; 
  </code></pre>
  
  <p>...then in my helper have:</p>
  
  <pre><code>public function switchTemplate()
  {
      $detect = new Mobile_Detect();
      if($detect-&gt;isMobile()){ 
          $template = 'catalog/category/mobile_view.phtml'; 
      }
      else{ 
          $template = 'catalog/category/view.phtml'; 
      }; 
      return $template;
  }
  </code></pre>
  
  <p>This works fine, but if I wanted to do something similar for other sections, for example the product detail page, I'd need to explicitly state each and every template in the helper.</p>
  
  <p>Can anyone think of any way that it could be used to maybe just prefix the default template or something? So for example with the list view, the default is <strong>catalog/category/view.phtml</strong> - so if viewing on a mobile you'd get <em>mobile_</em> prepended to the standard template, thus getting <strong>catalog/category/mobile_view.phtml</strong>?</p>
  
  <p>Or any other ideas on getting something similar accomplished? I'd like to be able to set things up from the local.xml, and not have to edit the helper every time I want to add a new mobile template.</p>
  
  <p>I also thought about an observer to add a "mobile" handle for using in the xml layouts, but not 100% if that would work.</p>
  
  <p>P.S. I know I could use a helper inside the template files to serve up different content for mobiles (I already do that) but I'm interested in the possibilities of doing this via a local.xml.</p>
  
  <p>P.S.2 also, just to note, the reason I'm not wanting to use the standard design exceptions is I might want to have desktop/tablet/mobile versions of files for example.</p>
  
  <p>Thanks in advance!</p>
  
  <p>ANSWER: Based on Simon's answer I did the following <a href="https://stackoverflow.com/a/22579344/161056">https://stackoverflow.com/a/22579344/161056</a></p>