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

×
×
  • Create New...