Modifying templates

From TNG_Wiki
Revision as of 14:11, 4 February 2011 by Bsl20b50 (talk | contribs) (Article creation.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article is intended to provide basic instructions for customizing and working with templates.

Introduction

In the template configuration menu (Admin >> Setup >> Configuration >> Template Settings), there are a number of fields which are essentially storing text variables. These variables are saved in templateconfig.php. The variables are then used in the template index.php, topmenu.php, or any other template specific place you wish to use them.

Understanding template variables

To create a new variable, first you need to understand the syntax of the text variables used in templates. I will use the example of the Main Paragraph text in template 8, but the principles apply broadly.

In template8/index.php, you will find the following:
<?php echo $tmp['t8_mainpara']; ?>
The components of this code are

  • <?php ... ?> - this opens php to find and display the variable.
  • echo - this displays the variable.
  • $tmp['....'] - this indicates that the variable is part of a template.
  • t8 - denotes which template the variable comes from.
  • mainpara - this is where the variable is defined.


In templateconfig.php, you will find something like:
$tmp['t8_mainpara'] = "This is where you can welcome a user to your site. You might also give them some basic information on navigating and links to any help or FAQ pages you may have.";

This looks very similar to what is in index.php. The main difference is that here the variable is defined. You may also notice in the Template Configuration menu that this text field allows for more text than some of the other fields. This is defined by admin_templateconfig.php around line 94. All variables that will be in the long format will show up in the following code:

$textareas = array('mainpara','searchpara','fhpara',...);

In your language folder, there is a line in text.php that looks something like:

$admtext['mainpara'] = "Welcome paragraph"; //1, 4, 6, 7, 8

This defines what is displayed in the Admin Template Configuration menu as the name of the variable. As you may notice, the core variable name is the same; the difference is $admtext instead of $tmp and t8_. After the semicolon is a comment that tells which templates use this variable. In this example, 1, 4, 6, 7, 8.

Creating and using new variables

To create and use a new variable, you need to add the variable in three places; templateconfig.php, cust_text.php, and the file that will display the variable (i.e. index.php or topmenu.php).
If I want to create a new variable for military records, I would do the following:

In templateconfig.php, I would add the following line in the appropriate template area. Replace 't8' with 't#' for whatever template you are using.

$tmp['t8_military'] = "";

Note that there is nothing between the quotes yet. In the template menu, it will show up as an empty box. When you enter text into the box and save your changes, templateconfig.php will be changed to reflect what you entered.

You also need to add the following line to cust_text.php in your language folder:

$admtext['military'] = "Military Records"; //8

The comments after the semicolon are not necessary, but may be helpful. This makes "Military Records" show up in your template configuration menu to the left of the edit box. If nothing is entered in cust_text.php, there will only be a colon before the box; no text.

IF you want a long format box, you will need to add the following to the array mentioned above in admin_templateconfig.php:

,'military'

Any changes made to this file need to be backed up or made into a mod file as it will be overwritten with upgrades.

Now you are ready to add your text to your index.php (or other file). Just add the following line to the appropriate file in the place you want it displayed:

<?php echo $tmp['t8_military']; ?>

If you are placing it within a php block, you will need to omit the php tags.