PDA

View Full Version : Template Determination



fang27
09-18-2014, 01:18 PM
Does anyone know where the template is pulled from the database? Meaning, which script calls up which template that has been set in the Admin?

(Meaning, which file is DIR_WS_TEMPLATES defined? Where is the info pulled from the database and the constant set?)

ridexbuilder
09-19-2014, 03:52 AM
This isn't relevant if making your own template.
http://wiki.oscdox.com/v2.5/bts_docs - though we have added a few new features, to assist with further customisation, see:
https://code.google.com/p/oscmax2/source/list

fang27
09-19-2014, 06:18 AM
This isn't relevant if making your own template.
http://wiki.oscdox.com/v2.5/bts_docs - though we have added a few new features, to assist with further customisation, see:
https://code.google.com/p/oscmax2/source/list

Didn't claim it was. Or what I was doing. I've created themes before.

This circumstance is different, so I will explain: I want users to be forced to a mobile website if they meet the criteria (i.e. their device matches a mobile device).

Since I wrote this, I found that it is in the function bts_template_switch() in the includes/configure_bts.php file where I could add code to test for a mobile device and serve up a different theme based on that.

If this is the proper (or only) place to do this, great. If it isn't, let me know!

ridexbuilder
09-19-2014, 06:33 AM
You can't expect a relevant response if not given the full story. :rolleyes:
Your methodology appears to be similar to that of the iOS contribution and is the initial route that I went down a good few months ago, whereby the user agent determines the 'profile' used. This is contrary to the bootstrap method that goes on the premise of mobile first and template determination by screen resolution i.e. dynamic sizing.
During my initial testing, I became concerned about the duplication of code and the ongoing maintenance of have distinct mobile pages. The bootstrap methodology helps to contain this with common code, at the expense of styling (CSS) complexity.

fang27
09-19-2014, 06:56 AM
You can't expect a relevant response if not given the full story. :rolleyes:
Your methodology appears to be similar to that of the iOS contribution and is the initial route that I went down a good few months ago, whereby the user agent determines the 'profile' used. This is contrary to the bootstrap method that goes on the premise of mobile first and template determination by screen resolution i.e. dynamic sizing.
During my initial testing, I became concerned about the duplication of code and the ongoing maintenance of have distinct mobile pages. The bootstrap methodology helps to contain this with common code, at the expense of styling (CSS) complexity.


Yeah, responsive vs. adaptive web design. I choose adaptive. :snooty:

As for relevant response: it would have been to simply answer the question. :rolleyes:

wkdwich
03-17-2015, 07:18 AM
fang have you made any progress on this project?

fang27
03-18-2015, 07:35 AM
fang have you made any progress on this project?

I did indeed: sorry for not posting back sooner!

The place where the template is determined is in the file configure_bts.php - near the bottom is "function bts_template_switch()" - within that you need to change the code to detect a mobile environment. I use the Mobile Detect (https://github.com/serbanghita/Mobile-Detect) script from Github.

Upload the Mobile_Detect.php file to the catalog/includes directory (or where-ever you want to put it) and change this code:




function bts_template_switch() {
if ((TEMPLATE_SWITCHING_ALLOWED == 'true') && (isset($_GET['tplDir'])) && is_dir(DIR_WS_TEMPLATES_BASE . basename($_GET['tplDir'])) ) {
$tplDir = basename($_GET['tplDir']);
tep_session_register('tplDir');
} else {
if ((tep_session_is_registered('tplDir')) && (TEMPLATE_SWITCHING_ALLOWED == 'true') && is_dir(DIR_WS_TEMPLATES_BASE . basename($_SESSION['tplDir']))){
$tplDir = basename($_SESSION['tplDir']);
}else{
$tplDir = DIR_WS_TEMPLATES_DEFAULT;
}
}

if ((preg_match('{^[[:alnum:]|_|-]+$}', $tplDir)) && (is_dir (DIR_WS_TEMPLATES_BASE . $tplDir))){
// 'Input Validated' only allow alfanumeric characters and underscores in template name
define('DIR_WS_TEMPLATES', DIR_WS_TEMPLATES_BASE . $tplDir . '/' );
} else {
if ($bts_debug === TRUE) { $illegal_directory = '<b>' . strip_tags($tplDir) . '</b> '; }
exit('<table width="100%" style="font-family: Verdana, Arial, sans-serif; font-size: 11px; line-height:1.5; background-color: #ffe6e6; border:solid 1px #ff8e90; padding:5px;"><tr><td align="center">Your template directory ' . $illegal_directory . 'can not be found. Please login to your admin panel and go to the <b>Default Template Directory</b> under <b>Templates</b> in the <b>Configuration</b> menu.</td></tr></table>');
}

return $tplDir;
}


to this:



function bts_template_switch() {
if ((TEMPLATE_SWITCHING_ALLOWED == 'true') && (isset($_GET['tplDir'])) && is_dir(DIR_WS_TEMPLATES_BASE . basename($_GET['tplDir'])) ) {
$tplDir = basename($_GET['tplDir']);
tep_session_register('tplDir');
} else {
if ((tep_session_is_registered('tplDir')) && (TEMPLATE_SWITCHING_ALLOWED == 'true') && is_dir(DIR_WS_TEMPLATES_BASE . basename($_SESSION['tplDir']))){
$tplDir = basename($_SESSION['tplDir']);
}else{
$tplDir = DIR_WS_TEMPLATES_DEFAULT;

//Newest detection script 2013-08-30
require '<<<directory path to>>>Mobile_Detect.php';
$detect = new Mobile_Detect;
//Check for mobile environment.
if ($detect->isMobile()) {
$tplDir = "mobile-template-directory-name";
}

}
}

if ((preg_match('{^[[:alnum:]|_|-]+$}', $tplDir)) && (is_dir (DIR_WS_TEMPLATES_BASE . $tplDir))){
// 'Input Validated' only allow alfanumeric characters and underscores in template name
define('DIR_WS_TEMPLATES', DIR_WS_TEMPLATES_BASE . $tplDir . '/' );
} else {
if ($bts_debug === TRUE) { $illegal_directory = '<b>' . strip_tags($tplDir) . '</b> '; }
exit('<table width="100%" style="font-family: Verdana, Arial, sans-serif; font-size: 11px; line-height:1.5; background-color: #ffe6e6; border:solid 1px #ff8e90; padding:5px;"><tr><td align="center">Your template directory ' . $illegal_directory . 'can not be found. Please login to your admin panel and go to the <b>Default Template Directory</b> under <b>Templates</b> in the <b>Configuration</b> menu.</td></tr></table>');
}

return $tplDir;
}



This all on Oscmax 2.54

I am sure there is smoother way of coding that, but I was in a hurry and haven't had time to go back to it. :whistle:

I am considering, eventually, releasing my mobile theme that I created.

pgmarshall
03-19-2015, 02:31 PM
I have used a similar approach to build a multi-site store using customer groups - ie. Customer group 1 = URL1, Customer group 2 = URL2

wkdwich
03-19-2015, 07:50 PM
Hey Fang, I'd love to test your template on my 2.0.35 installs to see if it will work there.. I'm going to look into what you posted up there and see if I can get it that far and switch to say fallback..

Oh.. does this put in the veiwport meta tag and the other things that google is now insisting every site has?

wkdwich
03-20-2015, 04:53 AM
well it works thats for sure.. Tech Threads : Tech Threads, 100% nylon salon vests and salon apparel and hair cutting capes. Best prices online with over 80 styles of Nail, barber, skin and hair stylist apparel at factory direct prices. Great for pet groomers, bakers and more! (http://www.nailtech.com/aprons) so now I have to figure out a "mobile" template" I'll go poke at osc to see what I can come up with

malcol27
04-09-2016, 12:12 AM
This does work but on my site if you enter using www as the prefix instead of the full domain name you are redirected to the full site. Also if you are on the mobile site any link that has www prefix opens to full site. Can anyone help me sort this out ?

malcol27
04-09-2016, 01:25 PM
This does work but on my site if you enter using www as the prefix instead of the full domain name you are redirected to the full site. Also if you are on the mobile site any link that has www prefix opens to full site. Can anyone help me sort this out ?

Hi, Seems to have been an issue with the session not carrying tplDir over to every page. I made a few small tweaks and it seems to work but I think this could just be related to my installation. If anyone has any similar experience with the site going from mobile to fallback post it here but for now it seems like a unique problem.