Understanding Template Settings - TNG V9

From TNG Wiki
Jump to: navigation, search
Construction The Understanding Template Settings - TNG V9 is currently under development, is not complete, and might not include all necessary information.
This information applies only to TNG V9 and above.
TNG 9.0
Construction


To understand how the Template Settings work in TNG V9, in order to create new templates or modify existing ones, you need to understand:

  • how the template folders should be named
  • how the variables should be named
  • how multiple languages are supported

Template Name Rules

The following is from an email posted by Linc Haymaker on the TNG V9 testers list.

The template naming rules for TNG V9 are as follows:

  • Do not use any template folders named XXX where XXX are numeric - Chars 0-9
So do not use template folders named 1, 11, 101 9.1 ...
  • Do not use template folders named like: 0xff, 0x00 and the like - Hexadecimal notation (0xFF)
  • Do not use template folders named like: 3e5, 2e2 and the like. - Scientific notation

If the user does not follow these rules they run the risk of:

  • Ending up with a template selection that will not function as desired.
Folder name vs prefix convention differences.
  • Two template selections within the the pulldown that look the same, but are not the same folder name.
Template folders named "template10" and "10" show the same in the pulldown.

If the above rules are followed then the prefix convention (short hand name) to be used within templateconfig.php and the template(s) index.php and topmenu.php (if used) is:

  • If template name is templateXXX where the name starts with "template" then the prefix naming convention for the template is: "tXXX"
  • If the template does not have templateXXX then the prefix naming convention is: "Ythe_folder_name_" where Y is "t"
Template folder name Display in pulldown prefix / Short hand name allowed / not allowed
template4 Template 4 t4 allowed
template10 Template 10 t10 allowed
10 Template 10 not allowed
template0x00 Template 0x00 t0x00 allowed
template3e5 Template 3e5 t3e5 allowed
3e5 Template 3e5 not allowed
template3t5 template3t5 ttemplate3t5 allowed
template10x template10x ttemplate10x allowed
abcde abcde tabcde allowed
template500 Template 500 t500 allowed
500 Template 500 not allowed
template500x template500x ttemplate500x allowed
500x 500x t500x allowed
templateblue templateblue ttemplateblue allowed

Note that if you use names instead of numbers for your template name, such as templateblue for example, you have to code the variables in the templateconfig.php as ttemplateblue_


Adding New Variables

When you add new variables to an existing TNG template, or create a new template, you may need to make changes in multiple places:

  • templateconfig.php
  • cust_text.php
  • admin_templateconfig.php
    • textarea array
    • translation array

templateconfig.php

You can add new variables directly in the templateconfig.php file and they will automatically be displayed in the Admin >> Setup >> Template Settings relative to where you added them in the file. For example, you could add the following variables to Template 4 to show a Feature 5

$tmp['t4_featuretitle5'] = "Feature Story 5";
$tmp['t4_featurelink5'] = "histories/feature5.php";
$tmp['t4_featurethumb5'] = "img/featurethumb4.gif";
$tmp['t4_featurepara5'] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.";

However, just adding the above variables to the templateconfig.php file is not sufficient, since these will display in the Template Settings for Template 4 without any text labels.

cust_text.php

So in addition to adding the template variables you need to create $text labels for these variables in your cust_text.php file for each language you support on your site.

        $admtext['featurethumb5'] = "Feature 5 thumbnail";
        $admtext['featurelink5'] = "Feature 5 link";
        $admtext['featuretitle5'] = "Feature 5 title";
        $admtext['featurepara5'] = "Feature 5 paragraph";



admin_templateconfig.php

translation array

Note that if you add new variables and also want these variables to support multilingual environments, you must also add the new variables to the $needtrans array in admin_templateconfig.php. So for the above on a multilingual site you will need to modify line 165 of admin_templateconfig.php to add featuretitle5 and featurepara5 to the array


    $needtrans = array('headline','maintitle','welcome','hisside','herside','headtitle1','headtitle2','headtitle3','momside','dadside','mainpara',
'featurepara','searchpara','fhpara','mwpara','respara','headtitle','headsubtitle','latestnews','featuretitle1','featuretitle2','featuretitle3',
'featuretitle4','featuretitle5','featurepara1','featurepara2','featurepara3','featurepara4','featurepara5','photocaption','newstext');

textarea array

In order to get the Feature 5 paragraph to be a <textarea> instead of a single input field, you must also add the featurepara5 to the $textareas array.

     $textareas = array('mainpara','searchpara','fhpara','fhlinkshis','fhlinkshers','mwpara','featurepara','respara','featurelinks','reslinks','headtitle','headsubtitle','latestnews','featurepara1','featurepara2','featurepara3','featurepara4','featurepara5','photocaption','newstext');

Multi-language example

TNG version: 9.0

In order to add a multi-language variable to a TNG V9 Template, you need to do the following:

  1. modify the $needtrans array in admin_templateconfig.php to add the tag name without the template identifier to the $needtrans array
  2. create a $admtext variable in your language cust_text.php for the same label tag added to the $needtrans array
  3. add the new template variable to the templateconfig.php file
  4. modify the index.php and topmenu.php files to use the new template variable

For example, if you wanted to change the Search and Title image files in Template 4 to use a different graphic image for each language you would need to

  1. add titleimg and searchimg to the $needtrans array as shown below to line 165 of admin_templateconfig.php
    $needtrans   =   array('headline','maintitle','welcome','hisside','herside','headtitle1','headtitle2','headtitle3','momside','dadside','mainpara','featurepara',
    'searchpara','fhpara','mwpara','respara','headtitle','headsubtitle','latestnews','featuretitle1','featuretitle2','featuretitle3','featuretitle4',
    'featurepara1','featurepara2','featurepara3','featurepara4','photocaption','newstext','titleimg','searchimg');
  2. add $admtext['searchimg'] to your cust_text.php for each language you use. The $admtext['titleimg'] is already provided by TNG
  3. add $tmp['t4_searchimg'] to your templateconfig.php file
    $tmp['t4_searchimg'] = "img/search4.gif";
  4. when you update your Template Settings for Template 4 and choose the Create copy in: pull down for the language selection, TNG will add
    $tmp['t4_searchimg_English-UTF8'] = "img/search4-en.gif";
    $tmp['t4_searchimg_French-UTF8'] = "img/search4-fr.gif";
  5. you then need to modify the Template 4 index.php file to use the new language switching capability for the graphic title and search image
    • line 14 of the index.php which displays the search4.gif file must be changed to use the new t4_searchimg variable as follows
      <a  href="searchform.php"><img src="<?php echo  $cms['tngpath'] .  $templatepath; ?><?php echo  getTemplateMessage('t4_searchimg');  ?>" alt="<?php echo  $text['mnusearchfornames']; ?>"  class="searchimg"  /></a>
    • line 91 of the index.php which displays the search4.gif file must be changed to use the new t4_searchimg variable as follows
      <img src="<?php echo  $cms['tngpath'] .  $templatepath; ?><?php echo  $tmp['t4_titleimg']; ?>" alt=""  class="banner" width="468"  height="100" />
  6. you then need to modify the Template 4 topmenu.php file to use the new language switching capability for the graphic title and search image
    • line 11 of the topmenu.php which displays the search4.gif file must be changed to use the new t4_searchimg variable as follows
      <a  href="searchform.php"><img src="<?php echo   $cms['tngpath'] .  $templatepath; ?><?php echo   getTemplateMessage('t4_searchimg');  ?>" alt="<?php echo   $text['mnusearchfornames']; ?>"  class="searchimg"   /></a>
    • line 80 of the topmenu.php which displays the search4.gif file must be changed to use the new t4_searchimg variable as follows
      <img src="<?php echo  $cms['tngpath'] .   $templatepath; ?><?php echo  $tmp['t4_titleimg']; ?>" alt=""   class="banner" width="468"  height="100" />

Note that if you want to use URL links in a Template Settings variable, then it must be defined in the $textarea

Displaying New Variables

echo statement

If you add new variables to the templateconfig.php, then you also need to add the echo for the variable in the index.php or topmenu.php file as appropriate. For example, if you could add the variables to Template 4 to show a Feature 5, then you need to modify the Template 4 index.php file to show the new added variables

<p>
<a href="<?php echo $tmp['t4_featurelink5']; ?>"><img src="<?php echo $cms['tngpath'] . $templatepath; ?><?php echo $tmp['t4_featurethumb5']; ?>" alt="feature 5" class="featureimg" /></a>
<a href="<?php echo $tmp['t4_featurelink5']; ?>"><span class="emphasis"><?php echo getTemplateMessage('t4_featuretitle5'); ?></span></a> <?php echo getTemplateMessage('t4_featurepara5'); ?>
</p>

getTemplateMessage

Note that if the variable is used to support multiple languages and is in the $needtrans array, then you must used the getTemplateMessage function to display the language specific variable content. In other words, any variable that you add to the $needtrans array should be displayed using a getTemplateMessage function call.

<?php echo getTemplateMessage('t4_featurepara4'); ?>

Note that in the echo getTemplateMessage('tN_variable'), the language specific extension for the variable is not specified, the getTemplateMessage function determines what language is in use and set the variable appropriately.


getTemplateMessage function

TNG V9 added the getTemplateMessage function to display the text variables in the index.php page in order to support Home pages for multiple languages.

function getTemplateMessage($key) {

    global $tmp, $session_language;

    $langkey = $key . "_" . $session_language;

    return isset($tmp[$langkey]) ? $tmp[$langkey] : $tmp[$key];
}

Preserving your changes

The best way to preserve your changes and potentially avoid major problems on TNG upgrades, is to code your changes as a .cfg file for the Mod Manager to install your changes.

If you prefer making your changes manually, then it is recommended that you keep good notes.

Related Links

Modifying templates

Creating a new Template - TNG V9

Multi-language Template Variables

Language Switching Graphic Titles