<tip c w>Warning: This is an advanced tutorial, involving making changes to PHP files.
Changes made using this tutorial can be undone using any of the pages in the admin panel under Design > admin menu, so be sure to keep a "local" copy of the customized file to re-upload.
Before attempting to make changes as described here, be sure you have a firm grasp of the basics, as everything described here builds on top of that.
Remember, support for PHP customizations as described in this tutorial are outside the scope of the support we offer for Geo support. Geo Support can try to help you with the how and where for editing PHP files, but they cannot make changes for you or try to troubleshoot problems related to customized PHP files.</tip>
Are you creating your own custom template design, but don't want everyone to see the changes until you are finished? Do you want certain people to be able to view the site using one template set, while others use another? Do you want to make it use a certain template set based on some other criteria?
What the tutorial specifically does, is walk you through the steps to set it up so that it will "load" a specific template set, if you go to a special URL. It can also be used by developers as a starting point for loading specific template set(s) based on some criteria, sort of as a "hello world" example.
<tip c n>Note: This tutorial instructs on how to allow a site to use different template sets based on certain criteria. This is not needed to simply change what template set is used normally, for that just change what template set(s) are marked as active in the admin at Design > Template Sets. For more info on how to actually create and use your own custom template sets, see the design basics tutorials.</tip>
This tutorial will walk you through the steps to set up your site, so that someone can view the site using specific custom template set just by viewing a special URL.
Skills
Instructions
<?php ########################################### ## Auto-generated file ## It is not recommended to edit ## this file directly, but you can ## if you want. ## ## Generated: Oct 5, 2010 17:07:16 ########################################### /** * To manually add your own template set, use the syntax: * * geoTemplate::addTemplateSet('folder_name'); * * Where folder_name is the directory name, relative to this current directory. * NOTE: Default template set is always added by system as the last template set * to load. You do not need to add the default tempalte set here. * * If you do not wish manual changes to be overwritten next time admin makes a * change, be sure to put them in the "custom section" below. */ if (!defined('IN_ADMIN')) { # [CUSTOM SECTION] # //Anything manually added to this section will be left intact even if changes //are made in the admin panel. //BOO! # [/CUSTOM SECTION] # } geoTemplate::addTemplateSet('my_templates');
If you are still only using the default template set, that last line will be replaced by a PHP Comment stating that there are no template sets. That is normal, however this setup is not common on "live" sites since most sites will need to have custom template set to make changes in. <
########## START Modification - Use special template set if they use special URL ############ $alt_template_set = "new_design"; //change new_design to match your new design $secretCode = 'special_secret_code_abc123'; //change if you want if (isset($_GET['use_template_set'])) { //set a cookie to remember it, but make the cookie only last as long as the //browser session setcookie('use_template_set',$_GET['use_template_set'],0,'/'); //set cookie global so it works for this page load $_COOKIE['use_template_set'] = $_GET['use_template_set']; } if (isset($_COOKIE['use_template_set']) && $_COOKIE['use_template_set'] == $secretCode) { geoTemplate::addTemplateSet($alt_template_set); } ########## END Modification ############
If your file happened to look like the example we displayed above, after making this modification the file would look like this:
<?php ########################################### ## Auto-generated file ## It is not recommended to edit ## this file directly, but you can ## if you want. ## ## Generated: Oct 5, 2010 17:07:16 ########################################### /** * To manually add your own template set, use the syntax: * * geoTemplate::addTemplateSet('folder_name'); * * Where folder_name is the directory name, relative to this current directory. * NOTE: Default template set is always added by system as the last template set * to load. You do not need to add the default tempalte set here. * * If you do not wish manual changes to be overwritten next time admin makes a * change, be sure to put them in the "custom section" below. */ if (!defined('IN_ADMIN')) { # [CUSTOM SECTION] # //Anything manually added to this section will be left intact even if changes //are made in the admin panel. ########## START Modification - Use special template set if they use special URL ############ $alt_template_set = "new_design"; //change new_design to match your new design $secretCode = 'special_secret_code_abc123'; //change if you want if (isset($_GET['use_template_set'])) { //set a cookie to remember it, but make the cookie only last as long as the //browser session setcookie('use_template_set',$_GET['use_template_set'],0,'/'); //set cookie global so it works for this page load $_COOKIE['use_template_set'] = $_GET['use_template_set']; } if (isset($_COOKIE['use_template_set']) && $_COOKIE['use_template_set'] == $secretCode) { geoTemplate::addTemplateSet($alt_template_set); } ########## END Modification ############ # [/CUSTOM SECTION] # } geoTemplate::addTemplateSet('my_templates');
<
http://example.com/index.php?use_template_set=special_secret_code_abc123 <
Do you want to show the design to someone else to get their feedback? Just give them the special URL, it will be something like this:
http://example.com/index.php?use_template_set=special_secret_code_abc123
Below are a few tips:
# [CUSTOM SECTION] #
and Before the line:
# [/CUSTOM SECTION] #
If you do it that way, when changes are made in the admin panel, you custom code will be left intact. Note that this functionality was Added in 5.1.1, if you have a previous version you will need to update to use this functionality. <
Tips for PHP Developers: (these require a little more "do it yourself PHP code")
$my_ip = '192.168.1.100';//change this to your own IP if ($_SERVER['REMOTE_ADDR'] == $my_ip) { geoTemplate::addTemplateSet($alt_template_set); }
<
if ($some_criteria_is_met) { //Just an example, this won't actually do anything unless you set $some_criteria_is_met before the if block... geoTemplate::addTemplateSet($alt_template_set); }
<