This is a documentation for Board Game Arena: play board games online !

Game layout: view and template: yourgamename.view.php and yourgamename yourgamename.tpl

De Board Game Arena
Salta a la navegació Salta a la cerca

These 2 files work together to provide the HTML layout of your game.

Using these 2 files, you specify what HTML is rendered in your game client interface.

In <yourgame.tpl>, you can directly write raw HTML that will be displayed by the browser.

Example: extract of "reversi_reversi.tpl":

  <div id="myhand_wrap" class="whiteblock">
    <h3>{MY_HAND}</h3>
    <div id="myhand">
    </div>
  </div>

WARNING

Your view and your template are supposed to generate only the BASE layout of the game

You shouldn't try to setup the current game situation in the view: this is the role of your Javascript code. Why? Because you'll have to write Javascript code to put game elements in place anyway, and you don't want to write it twice :)

Example of things to generate in your view:

  • The overall layout of your game interface (what is displayed where).
  • The board and fixed elements on the board (ex: places for cards, squares, ...).

Example of things that shouldn't be generate by your view:

  • Game elements that come and go from the game area.
  • Game elements that are moving from one place to another.

phplib template system

BGA is using the phplib template system, used for example in PHPbb forums.

More details about how to use phplib template system here: http://www.phpbuilder.com/columns/david20000512.php3

Variables

In your template ("tpl") file, you can use variables. Then in your view (".view.php") file, you fill these variables with value.

In the example above, "{MY_HAND}" is a variable. As you can see, a variable is uppercase characters border by "{" and "}".

To give a value to this variable in your view.php:

Examples:


   // Display a translated version of "My hand" at the place of the variable in the template
   $this->tpl['MY_HAND'] = self::_("My hand");

   // Display some raw HTML material at the place of the variable
   $this->tpl['MY_HAND'] = self::raw( "<div class='myhand_icon'></div>" );

Blocks