{{indexmenu_n>40}} ====== Template Set Loading ====== **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 [[tutorials/design/start|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. 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. **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 [[/admin_menu/design/template_sets/start|Design > Template Sets]]. For more info on how to actually create and use your own custom template sets, see the [[tutorials/design/start|design basics]] tutorials. 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** * Comfortable with using FTP (to upload and download files from your site) < * Basic understanding of how PHP works will help, but not necessary. < **Instructions** - Turn off Geo cache, if currently turned on, in your admin at **Site Setup > Cache**.((Be sure to keep the cache turned OFF for as long as you are viewing the site with an alternate template set. Otherwise it will cache your alternate template set any time you view the site using it, so that "normal" users will end up seeing the alternate template set!)) < - In your admin, at **Design > Template Sets**, ensure that the template set(s) that you want to have active "by default" are used. That is, the template set you want to be used when a visitor views the website for the first time. < - For the purpose of this tutorial, we will assume your "main" template set is **my_templates** and the "special" template set is "new_design". In the rest of the instructions, it uses "new_design", just change that to be whatever you have named the folder for your template set, it will be the same as what is listed under "template sets not used" in the admin. < - Download and open the file **geo_templates/t_sets.php** ((If you do not see that file on your site, in your admin at **Design > Template Sets** just click save and it will create the file.)). The file will look something like this: 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. < - Add the following code between the **# [CUSTOM SECTION] #** and **# [/CUSTOM SECTION] #** lines (anything added between these lines will NOT be removed when 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 ############ If your file happened to look like the example we displayed above, after making this modification the file would look like this: < - Save the changes, and upload the file. < - View the front page of your site. Does it still display correctly? If not, un-do the changes you made (especially if on a live site). If your site does display correctly, continue. < - To see your site using the //new_design// template set, view your site, and add **?use_template_set=special_secret_code_abc123** to the URL. If your site was installed at //example.com//, the URL would be: http://example.com/index.php**?use_template_set=special_secret_code_abc123** < - This sets a cookie((Note that it sets, and uses, the cookie in the same block of custom code, the cookie is not otherwise used in the system besides what is done for the modifications to the t_sets.php file)) so that when you browse the site, until you close your browser, it will continue to use the "new_design" template set. The cookie is configured to expire when you close the browser window, to prevent someone from turning it on, then forgetting about it. < 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** ===== Tips ===== Below are a few tips: * If you are afraid that someone you do not want to see the new design, might guess the **special URL**, and want to make it harder for them to figure out: You can change that code to be whatever you want in the **t_sets.php** file. You would then use a different URL based on what you changed the //code// to be. < * You don't have to name the template set "new_design", it can be whatever you want it to be. In the instructions above, you would substitute your own template set name wherever you saw "new_design". < * Remember to keep your changes to be located **after** the line: # [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. < * If you do not see the lines noted in the above note, and you are using at least version **5.1.1**, in your admin panel at **Design > Template Sets** make a change to what template sets are active and save changes, then change the settings back and save changes again. That will re-create the **t_sets.php** file with the above section added. < **Tips for PHP Developers:** (these require a little more "do it yourself PHP code") * Instead of the checks above that use a combination of cookies and special URL to activate it, you could load the new_design template set according to your own IP. That way it always uses the "new design" when you view your own site from a specific location. An example of what this might look like: $my_ip = '192.168.1.100';//change this to your own IP if ($_SERVER['REMOTE_ADDR'] == $my_ip) { geoTemplate::addTemplateSet($alt_template_set); } < * You could load a template set according to whatever crazy criteria you can think up, something like 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); } < * When working with //user input//((This goes without saying, but...)), remember to **take security precautions** to ensure the user input is //cleaned// and is not used in a way that could be abused.<