Jump to content

Best approach on alternative template


ptjedi
 Share

Recommended Posts

Hi all,

I was thinking what's the best approach for a multi-themed website. The point of this is to build a website that has a simple website for mobile within a subdomain (m.domain.com, for example). How can this be achieved? I assume everything would be easy if there would be another "/site" folder. Is this it? If so, how can that be achieved?

Many thanks in advance!

Cheers

Link to comment
Share on other sites

I am doing this at the moment. Using apeisa's multisite module. m.domain.com is a separate page and has its tree. For redirection of mobile users I use Tera-Wurfl. For SEO purposes remember about canonical URLs. It would be great if every page had redirection to corresponding mobile page, but if someone came back from mobile to desktop version (you should provide such a link), leave him there - I am working on it currently (for someone who is not coder, it's not so easy :) ).

EDIT: diogo was first :)

  • Like 1
Link to comment
Share on other sites

I've checked that module (thanks diogo and jukooz) but like jukooz said, it seems I have to have a separate tree of pages for this website. Wouldn't it be simpler to have all my templates duplicated (head.inc to m-head.inc, for example) and then figure a way to match things? In other words, if I needed a theme switcher (and no extra domain) would that module seem fit for the job in your opinion?

Link to comment
Share on other sites

Not tested, but you can put this the top of the template to test the domain $_SERVER['HTTP_HOST'] and serve a different template depending on it

if($_SERVER['HTTP_HOST'] == m.domain.com) {
// code for mobile
}else{
// normal code
}
  • Like 1
Link to comment
Share on other sites

Not tested, but you can put this the top of the template to test the domain $_SERVER['HTTP_HOST'] and serve a different template depending on it

if($_SERVER['HTTP_HOST'] == m.domain.com) {
// code for mobile
}else{
// normal code
}

That's an idea I had as well. I was just checking if anyone had a more elegant solution to the problem.

Thank you and that will come in handy, however my question resides more on the part of "theme/template switching" rather than mobile detection.

Link to comment
Share on other sites

You can point the subdomain to your normal main domain. From there you could use a "proxy" page to "load" a template to load the page.

An elegant solution might be to use have your templates use the same "proxy" template. The alternative template name setting can be used to do this found in advanced tab.

Then create a proxy.php in the /site/templates folder. Here a code example:

if($_SERVER['HTTP_HOST'] == m.domain.com) {
  // template for mobile
  include("./mobile/".$page->template->name.".php");
}else{
  // desktop template
  include("./default/".$page->template->name.".php");
}

Then put your different templates each to a corresponding subfolder.

/site/templates/mobile/...

/site/templates/default/...

Another route would be to try symlink PW core folder and separate the site folders and use the same database and setting in config.php or symlink it too. This of course requires you to be able to create symlinks on the server.

processwire/wire

processwire/site

/assets

/modules

domain.com

/wire (symlink to processwire/wire)

/site (local)

/modules (symlink to processwire/site/modules)

/assets (symlink to processwire/site/assets )

/templates (local)

sub.domain.com

/wire (symlink to processwire/wire)

/site (local)

/modules (symlink to processwire/site/modules)

/assets (symlink to processwire/site/assets )

/templates (local)

I think this is easy possible, just have to make sure same template files exists in both local /site/templates folder.

I would try something with first example.

  • Like 2
Link to comment
Share on other sites

  • 2 months later...

Hi,

I'm experiencing Cache issues here trying to make the whole thing work. I'm using a session variable in each template to figure out which code to serve and everything works fine as long as I'm logged into the admin panel. If not, the whole system switches to random. I'm not yet all that familiar with PWs caching mechanism so has anyone got tips for me?

Thanks,

thomas

Link to comment
Share on other sites

You should use markupCache module instead and cache only parts of your output.

So your code might be something like that:

<?php
$cache = $modules->get("MarkupCache");
switch($session->typeOfVisitor) {
 case "lucky":
   if(!$data = $cache->get("lucky")) {
  $data = "You are lucky"; // Here you would actually get the real output...
  $data->save($data);
   }
   echo $data;
   break;
 case "unlucky":
   if(!$data = $cache->get("unlucky")) {
  $data = "You are unlucky"; // Here you would actually get the real output...
  $data->save($data);
   }
   echo $data;
   break;
}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By franciccio-ITALIANO
      Hi everyone.
      I've created 12 templates that are the same but each with an extra bit of html code. 
      The piece of code is as follows:
      <div> <div class="box-pf"> <i class="fa fa-map-pin fa-2x fa-red faa-pulse animated"></i> <a href=""> <span class="uk-text-middle"><i>Sonchus oleraceus</i> 'Grespino degli Orti'</span></b> </a> </div> </div> On the third line we read "fa-red."
      I created 12 similar templates.
      The first template has only one box with fa-red, the last template has 12 boxes with icons of 12 different colors.
      So. is there any way to have only 1 template and add, if I want and when I want, a small or big, same or different piece of html code?
       
    • By Kai
      REMOVED Free Processwire Template
    • By jploch
      Admin Theme Canvas
      A minimal admin theme with optimised page editor UI, based on Uikit 3.
      Currently this is close to stable, but users are advised to be cautious and test thoroughly.
      This theme is tested in all major Browsers including IE 11, Edge (>85), Chrome (>85), Firefox (>81), Safari (>11).

      If you find any bugs or have ideas for improvements, feel free to post your feedback.
      Download from Github
      Download from Modules Page
      Features
      Minimal black and white admin theme Fixed masthead navigation Direct access to page tree navigation inside page dropdown Less distraction for editors (when editing a page, the tabs are displayed as a dropdown menu inside the main navigation) Options to customise the ui Less distraction for editors

      Direct access to page tree navigation inside dropdown

      Page tree

      Options to customise the ui

      Login (inspired by AdminThemeBoss)

      Requirements
      Process Wire 3.0.100 or greater
      Installation
      Go to “Modules > Site > Add New“ Paste the Module Class Name “AdminThemeCanvas“ into the field “Add Module From Directory“ Click “Download And Install“ On the overview, click “Download And Install“ again… On the following screen, click “Install Now“ Go to your user profile page and change the theme to Admin Theme Canvas
    • By Brian Peat
      Hello! I've got a single client on Processwire and it's completely foreign to me. I've been able to find most things, but they've asked for a custom designed page with a full width header image/section, and then a body block and a right side bar below the header. They're using a landing page template, so I duplicated that, figured out how to add it in the admin, and assigned it to the page. Nothing. It doesn't change a thing.
      I feel like I'm missing something obvious. I've made sure all the fields are the same, I tried to set up the parent/child stuff though this page doesn't have a parent that I can tell (though it's under Landing Pages). If I can get the template to actually kick in, I think I can use a bit of code to check for the hero section and load it at the top. I also made a copy of the widget template and set that to load instead of the original. But again, since my main page template isn't kicking in, neither is the new widget template.
      I'd just love some tips on what to check or change to get a landing page to actually render what's in the assigned page template.
      Hopefully I've used the correct terminology here to make sense.
      Thanks!
    • By rookie
      hi there,
      Is there a module or other solution to select a template with a preview image? Sometimes it is not that easy to describe a template.
      e.g. Template with 3 columns (image, title, content, button) or template for a slider with max. 4 pictures.
      Even if it is nice to have a description field for a template, a picture says more than thousand words could describe.
      And no, I don't think I could develop something like that. I don't even know where to start.🙄
×
×
  • Create New...