Answers.Body: <p>To use separate templates I created plugin and within <code>init()</code> method I overwritten <a href="https://craftcms.com/classreference/services/TemplatesService#templatesPath-detail" rel="nofollow noreferrer">templatesPath</a> variable. Seems to be working although you need to test it with other plugins as I have tested it with fresh Craft instance only.</p>
  
  <pre><code>public function init() {
      $templatesPath = craft()-&gt;templates-&gt;getTemplatesPath();
  
      if(craft()-&gt;request-&gt;isMobileBrowser()){
          $templatesPath .= 'mobile/';
      } else {
          $templatesPath .= 'desktop/';
      }
  
      craft()-&gt;templates-&gt;setTemplatesPath($templatesPath);
  }
  </code></pre>
  
  <p><a href="https://craftcms.com/classreference/services/HttpRequestService#isMobileBrowser-detail" rel="nofollow noreferrer">isMobileBrowser()</a></p>
  
  <p>This example assumes that <code>templates</code> folder contains <code>mobile</code> and <code>desktop</code> folders. Both have a mirror template files structure. Also you don't need m.domain.com anymore.</p>
  
  <hr>
  
  <p>But it you need m.domain.com you can use <a href="https://craftcms.com/docs/multi-environment-configs#environment-specific-variables" rel="nofollow noreferrer">multi environment config variables (environmentVariables)</a> or stick to the previous solution.</p>
  
  <pre><code>return array(
      '*' =&gt; array(
          'templatesPath' =&gt; 'desktop',
      ),
      'm.domain.com' =&gt; array(
          'templatesPath' =&gt; 'mobile',
      ),
  );
  
  public function init() {
      $templatesPath = craft()-&gt;templates-&gt;getTemplatesPath();
  
      if(craft()-&gt;config-&gt;get('environmentVariables')['templatesPath']){ //this line changed
          $templatesPath .= 'mobile/';
      } else {
          $templatesPath .= 'desktop/';
      }
  
      craft()-&gt;templates-&gt;setTemplatesPath($templatesPath);
  }
  </code></pre>
  
  <hr>
  
  <p>To force mobile URL insert this code to desktop base layout file:</p>
  
  <pre><code>if(craft.request.isMobileBrowser()) {
      {% redirect 'http://m.domain.com' %}
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-01T17:24:11.690Z
Answers.LastActivityDate: 2016-11-01T17:49:44.657Z
Answers.LastEditDate: 2016-11-01T17:49:44.657Z
Answers.UserDisplayName: Krzysztof Boduch
Body: <p>I have an upcoming project where it may be necessary to have a mobile site and a desktop site as the desktop design will not work well responsively.</p>
  
  <p>I built a similar site recently in ExpressionEngine and used Multiple Site Manager (MSM) which allowed me to have separate templates with the same url structure pulling content all from the main site. Since that build I've starting moving new projects to Craft and would like to find a solution to this.</p>
  
  <p>Since Craft does not have a feature similar to MSM, at this point, what would be the best way to approach this. Urls need to be the same on both domain.com and m.domain.com with all content being sharing the same channels.</p>
  
Tags: <templating>
Title: How to run domain.com and m.domain.com from one install
ThreadText: # How to run domain.com and m.domain.com from one install
  
  (Asked by: username_0 on 2016-11-01)
  
  I have an upcoming project where it may be necessary to have a mobile site and a desktop site as the desktop design will not work well responsively.
  
  I built a similar site recently in ExpressionEngine and used Multiple Site Manager (MSM) which allowed me to have separate templates with the same url structure pulling content all from the main site. Since that build I've starting moving new projects to Craft and would like to find a solution to this.
  
  Since Craft does not have a feature similar to MSM, at this point, what would be the best way to approach this. Urls need to be the same on both domain.com and m.domain.com with all content being sharing the same channels.
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-01. Score: 2 | Accepted answer
  
  To use separate templates I created plugin and within `init()` method I overwritten [templatesPath](https://craftcms.com/classreference/services/TemplatesService#templatesPath-detail) variable. Seems to be working although you need to test it with other plugins as I have tested it with fresh Craft instance only.
  
  ```
  public function init() {
      $templatesPath = craft()->templates->getTemplatesPath();
  
      if(craft()->request->isMobileBrowser()){
          $templatesPath .= 'mobile/';
      } else {
          $templatesPath .= 'desktop/';
      }
  
      craft()->templates->setTemplatesPath($templatesPath);
  }
  
  ```
  
  [isMobileBrowser()](https://craftcms.com/classreference/services/HttpRequestService#isMobileBrowser-detail)
  
  This example assumes that `templates` folder contains `mobile` and `desktop` folders. Both have a mirror template files structure. Also you don't need m.domain.com anymore.
  
  ---
  
  But it you need m.domain.com you can use [multi environment config variables (environmentVariables)](https://craftcms.com/docs/multi-environment-configs#environment-specific-variables) or stick to the previous solution.
  
  ```
  return array(
      '*' => array(
          'templatesPath' => 'desktop',
      ),
      'm.domain.com' => array(
          'templatesPath' => 'mobile',
      ),
  );
  
  public function init() {
      $templatesPath = craft()->templates->getTemplatesPath();
  
      if(craft()->config->get('environmentVariables')['templatesPath']){ //this line changed
          $templatesPath .= 'mobile/';
      } else {
          $templatesPath .= 'desktop/';
      }
  
      craft()->templates->setTemplatesPath($templatesPath);
  }
  
  ```
  
  ---
  
  To force mobile URL insert this code to desktop base layout file:
  
  ```
  if(craft.request.isMobileBrowser()) {
      {% redirect 'http://m.domain.com' %}
  }
  
  ```
  
  
  ---
  
  