asphyx

Paintings and drawings portfolio

Tuesday, January 5, 2010

XNova Legacies 2009.2: Menu and template management

Abstract

The purpose of this quick howto is to describe the way XNova manages templates and language files (I have not found docs about this on the official board).

This example adds an entry in the XNova main menu.

Clicking on this new entry will display a simple table with two columns.

Sources

XNova Template & menu management HowTo.zip Version: 1.0
5.1 KiB 1453 Downloads Details...

Code

Adding a menu entry

Edit \xnova\templates\OpenGame\left_menu.tpl and add a link (ex: {Test})

<td colspan="2"><div><a href="test.php" target="{mf}">{Test}</a></div></td>
 </tr><tr>

Add the entry language

French is used in this example.

Edit \xnova\language\fr\leftmenu.mo and add the {Test} translation (ex: “Nom du lien”)

$lang['Test']           = 'Test';

Describe the fields used by the script

Create \xnova\language\fr\test.mo and describe the values used in the script.
Example:

<?php
$lang['Field1']    = "Field 1";
$lang['Field2']    = "Field 2";
?>

Create a template which will be displayed to users

Create \xnova\templates\OpenGame\test.tpl and define the page structure, with  the position of the fields set up in test.mo
Exemple:

<br><br>
<table style="text-align: left; width: 750px;" border="0" cellpadding="0" cellspacing="1">
<tbody>
<tr>
<td>{Field1}</td>
<td>{Field2}</td>
</tr>
</tbody>
</table>
<br>

Script creation

Create \xnova\test.php

Include the common variables:

define('INSIDE' , true);
define('INSTALL' , false);
require_once dirname(__FILE__) .'/common.php';

Include the language file defined at step 3:

includeLang('Test');

Initialize the page and fields data variables:

$page    = "";
$parse    = $lang;

Fill the fields used in your template in an array. In this example, sample strings are used.

$parse['Field1'] = "Champ 1";
$parse['Field2'] = "Champ 2";

Build the page by giving this array to your template created at step 4:

$page = parsetemplate(gettemplate('test'), $parse);

Display the page in “User mode” (viewable by everyone):

display($page, $lang['test'], false);

Files list

  • \xnova\templates\OpenGame\left_menu.tpl
  • \xnova\language\fr\leftmenu.mo
  • \xnova\language\fr\test.mo
  • \xnova\templates\OpenGame\test.tpl
  • \xnova\test.php
posted by asphyx at 17:55  

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Powered by WordPress