User Tools

Site Tools


Sidebar

tutorials:design_adv:template_set_loading

This is an old revision of the document!


Table of Contents

Template Set Loading

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 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.

Requires Geo 4.0.0

<tip c n>Note: This tutorial instructs on how to allow a site to use different template sets based on certain criteria. For more info on how to actually create and use your own custom template sets, see the other tutorials in this section of the user manual.

These instructions can be used "in place of" or "in addition to" the steps from other tutorials that instruct you to click the Use Set button to start using a custom template design.</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

  • Comfortable with using FTP (to upload and download files from your site) <
  • Basic understanding of how PHP works will help, but not necessary. <

Instructions

  1. Turn off Geo cache, if currently turned on, in your admin at Site Setup > Cache. <
  2. In your admin, at Templates > Template System, ensure that the template set(s) that you want to have loaded "by default" are used. That is, the template set you want to be used when a visitor views the website for the first time. <
  3. 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. <
  4. Download and open the file geo_templates/t_sets.php 1). The file will look something like this:
<?php
###########################################
## Auto-generated file
## It is not recommended to edit
## this file directly, but you can
## if you want.
## 
## Generated: Apr  7, 2009 14:39:53
###########################################

 
/**
 * 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.
 */
 
geoTemplate::addTemplateSet('my_templates');

If you are 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. <

  1. Add the following code after the "*/" and before the next line that has text on it:
##########  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
	set_cookie('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: Apr  7, 2009 14:39:53
###########################################

 
/**
 * 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.
 */
 
##########  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
	set_cookie('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 ############

geoTemplate::addTemplateSet('my_templates');

<

  1. Save the changes, and upload the file. <
  2. 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. <
  3. To see your site using the new_design template set, view your site, and add ?use_template_set=special_secret_code_abc123. If your site was installed at example.com, the URL would be http://example.com/index.php??use_template_set=special_secret_code_abc123 <
  4. This sets a cookie 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 someone you don't want to see the new design might guess the special URL since it is published here: 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".

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 input2), remember to take security into account.<
1)
If you do not see that file on your site, in your admin click "Use Set" next to one of your template sets, then click "Reset Sets", so that the Template System will generate the file for you with no template sets loaded.
2)
This goes without saying, but…
tutorials/design_adv/template_set_loading.1239136991.txt.gz · Last modified: 2014/09/25 16:55 (external edit)