GAMESCRIPT.NET TEMPLATING SYSTEM
--------------------------------
--------------------------------
Intro
-----
This is a brief tutorial that will outline how to create a new template for the arcade script found at GameScript.net. The templating system consists of a number of .tpl files, a CSS file (optional) and a number of variables some of which are optional. The best way to familiarize yourself with the templating system is to study the example in your templates folder called 'basic'. If you decide to try and edit this template please make sure to back it up first just incase you make a mistake.
All files must exist in a sub folder within the scripts 'templates' folder (../templates/my_template). You may call the folder anything you choose.
The following .tpl files MUST be present in the folder you create:
category_container.tpl
category_content.tpl
category_games_row.tpl
footer.tpl
game_container.tpl
header.tpl
index.tpl
index_content.tpl
latest_games.tpl
play_content.tpl
top_games.tpl
You may also create additional files for any other content you wish to place on your site. For example if you wish to create an 'About Us' page you would create a page called 'about_us.tpl' and place it within your folder.
As mentioned above certain variables need to exist within the above named tpl files for the system to work correctly. Some are optional some are mandatory.
Here is a list of the variables with a brief explanation of it's purpose for each tpl file:
category_container.tpl
- $category_name [optional but recommended]
Holds the name of the current category. You can add this in multiple places if you wish.
- $games [mandatory]
This variable holds the content of games_container.tpl and games_row.tpl and is mandatory.
- $category_id [mandatory]
This variable holds the 'id' of the current category and is used in the url for the 'more...' link. You may wish to suppress the 'more' link on the 'category' page. An example of this can be found in the 'default' template.
category_content.tpl
- $games_content [mandatory]
This holds the content from the 'category_container.tpl' which in turn holds the games information.
- $latest_games [optional but recommended]
Holds the contents of the 'latest_games.tpl' and can be placed anywhere on the page.
category_games_row.tpl
- $game_X (where x is the index number of the game).
This is a very variable and it's count MUST correspond to the number you have set in your 'config' file for the variable '$category_games_per_row'. For example if the '$category_games_per_row' variable is set to '3' you would need to have 3 corresponding '$game_X' variables so you would have - $game_1, $game_2 and $game_3. These variables hold the information for each game. The layout of each game is described in 'game_container.tpl'.
footer.tpl
- No variables in this file.
game_container.tpl
- $game_id [mandatory]
This variable holds the 'id' number for each game and is used in the various links that lead to each game. These links should appear in the format 'index.php?action=play&id=<?=$game_id?>'.
- $game_thumb [optional but recommended]
Holds the location of the games thumbnail image.
- $game_description [optional but recommended]
Holds the description of the game.
game_row.tpl
- $game_X [mandatory]
See the explanation above for 'category_games_row.tpl'.
header.tpl
- $title [optional]
Holds the site title as defined in your 'config.php' file.
- $games_today [optional]
Holds the count of the total games played today. You may also place this on any of the templates ending in '_content.tpl'.
- $select_options [optional]
Holds the option list containing all the games currently set to 'active' within your database. This may also be placed on any of the templates ending in '_content.tpl'.
index.tpl
- $template_path [mandatory]
This holds the complete path to your template folder and should be used to prefix anything within your templates when the script needs to access the folder. Places such as before a link to your style sheet or image folder. You MUST NOT include the trailing '/' after it. For example this would be a link to your style sheet - <?=$template_path?>style
- $title [optional]
Holds the title of your site as defined in your 'config.php' file.
- $game_name [optional]
Holds the currently selected games name. Only available when you are on the game play page. Can be used in multiple places within this template.
- $header [mandatory]
Holds the output from your 'header.tpl'
- $content [mandatory]
Holds the output of the various content templates.
- $footer [mandatory]
Holds the content of your 'footer.tpl'
index_content.tpl
Refer to 'category_content.tpl' above.
latest_games.tpl
The section of code contained in this template MUST be present to display your list of 'Top Games'. The code looks like this:
<?php foreach($latest_games as $game): ?>
<a href='index.php?action=play&id=<?=$game['id']?>' class='gameLink'>
<?=$game['name'];?></a><br />
<?php endforeach; ?>
[refer to the example in the 'basic' template for suggested placement]
play_content.tpl
- $category_id
Holds the selected games corresponding category ID and is useful for creating a 'bread crumbs' type navigation.
- $category_name
Holds the selected games corresponding category name and is useful for creating a 'bread crumbs' type navigation.
- $game_width
Holds the width specified in the database for displaying the currently selected game. Used in the flash set up script.
- $game_height
Similar to $game_width but for the height of the game.
- $game_name
Holds the name of the currently selected game.
- $game_plays
Holds the total number of plays for the selected game.
- $game_description
Holds the description for the selected game.
- $latest_games
See above
- $top_games
See above
top_games.tpl
Similar to the 'latest_games.tpl' above this template has a section of code that MUST appear. You may customize it's display by wrapping it in html but the basic code should remain. The code looks like this:
<?php foreach($top_games as $game): ?>
<a href='index.php?action=play&id=<?=$game['id']?>' class='gameLink'>
<?=$game['name'];?>
</a> -
<em><?=$game['played']?></em>
<br />
<?php endforeach; ?>
**Important**
Remember that the $template_path needs to be placed before anything that will need to reference your custom template folder such as style sheets, images etc. It is available to the following templates:
index.tpl
header.tpl
footer.tpl
latest_games.tpl
top_games.tpl
category_content.tpl
category_container.tpl
game_container.tpl
index_content.tpl
play_content.tpl
It is also available to any custom template you create ('about_us.tpl','help.tpl' etc)
Creating A Template
-------------------
The basic steps for creating a template are as follows:
1. Create the layout in your favorite graphics program (Photoshop etc).
2. Slice up the layout and construct it in your favorite Web building package (Dreamweaver etc).
3. Separate the various sections of the html into their corresponding template files. This stage can take some time but once you are used to it it can be accomplished relatively quickly.
4. Place all the variables within each corresponding template.
5. Place all templates, style sheets, graphics etc in a folder. Name the folder and place it within your 'templates' folder.
6. Set the variables in your 'config.php' file to correspond with your new template.
7. Finished.
Support
-------
If you have any questions or need help please direct them to our community forum at
http://www.gamescript.net