Translations of this page?:

http://www.btiteam.org

Темплейт Система

Какво е това?

bTemplate използван в xbtit, е php class, който ни позволява да разделяме код(php) от html(темплейт), използвайки елементарни примки и if твърдения.
При разглеждането, от гледна точка на програмист е странно (особенно в началото) отколкото имайки целия (php код и html) готов в същият файл, но като дизайнер или тракер админ е чудесна възможност!
Вие можете да промените целия аспект на сайта си без да търсите html код в php кода, както при стария btit, едно от най-големите предимства е, намаляване на възможността за грешки(типични или в кода) и е много по-сигурно.

Как изглежда?

Както споменах по-горе, темплейт системата се систои от (най-малко) 2 части:

  • пример:
<br />
 
<table class="lista" cellpadding="0" cellspacing="0" <tag:block_width /> align="center">
  <tr>
    <td class="block" align="center" height="20px"><b><tag:block_title /></b></td>
  </tr>
  <tr>
    <td width="100%" align="<tag:block_align />" valign="top">
    <tag:block_content />
    </td>
  </tr>
</table>

Може да видите, че тук е само чист html, всички променливи които ще бъдат променени от php кода се наименоват така ”<tag:var_name />”, тогава нашият php код ще има нужда само да извика $btemplate→set(“var_name”,$phpvar); за да замени var_name с $phpvar стойността.
Тогава, ако искате да промените само изгледа на един блок, ще Ви се наложи да промените само този темплейт (block.tpl) и css класовете.

  • php кода (показва функциите на блоковете, може да ги намерите в functions.php):
1.function set_block($block_title,$alignement,$block_content,$width100=true)
2.{
3.    global $STYLEPATH, $TABLE_PREFIX, $language;
4.
5.    $blocktpl=new bTemplate();
6.    $blocktpl->set("block_width",($width100?"width=\"100%\"":""));
7.    $blocktpl->set("block_title",$block_title);
8.    $blocktpl->set("block_align",$alignement);
9.    $blocktpl->set("block_content",$block_content);
10.    return $blocktpl->fetch(load_template("block.tpl"));
11.
12.}

Тук не се вижда, но разбира се, Вие трябва да извикате bTemplate.php (ако не е вече направено от xbtit).
линия 5: Създаваме нов btemplate's пример
от линия 6 до линия 9: Задаваме някои променливи стойности към някои btemplate's тагове (ако погледнете в темплейт файловете, ще намерите точно същите <tag:block_* /> както са зададени тук.
линия 10: казва кой клас темплейта да зареди и тогава обстойно(променя) предишно зададените тагове с точните стойности.

Изгубихте се?

По-трудно е да се обесни как да използваме темплейт системата отколкото да я използваме… Добро начало (и тест) може да бъде bTemplate Documentation.

Concrete xbtit use

In xbtit distribution, the tpl's files (templates) are present only in xbtit_default's style, why?
Interesting question ;-)
xbtit always use xbtit_default/*.tpl unless it find requested tpl into requested style. Ehm, I know, seems to be a crazy explanation, then let us do an example:
the torrent's list display have some missed columns (compared to btit), then let us suppose you want to keep the default style as is (and I personally recommend to keep it original) and change the aspect of “Frosted”'s one (by adding torrent's size and uploader).

  • copy torrent.list.tpl from xbtit_default to frosted's folder
  • open frosted/torrent.list.tpl
  • e.g. after:
          <td align="center" width="30" class="header"><tag:torrent_header_complete /></td>

add:

          <td align="center" width="30" class="header"><tag:torrent_header_uploader /></td>
          <td align="center" width="30" class="header"><tag:torrent_header_size /></td>

and after:

          <td align="center" width="30" class="lista" style="text-align: center;"><tag:torrents[].complete /></td>

add:

          <td align="center" width="30" class="header"><tag:torrents[].uploader /></td>
          <td align="center" width="30" class="header"><tag:torrents[].size /></td>
  • save


In this specific case we don't have to change php code, because in default code the same columns as in btit are filled.
You can see here to type of bTemplate's tag:

  • <tag:torrent_header_size /> is the simplest as we saw above.
  • <tag:torrents[].uploader /> is a little bit different, because in the code it's defined as array (something like $torrent[“uploader”])

You find more info on tag's type on bTemplate's Documentation.

Ако се логнете във вашият торент сайт и се загледате в списъка с торенти, ще забележите, че използването на стила xbtit_default е не точно същият както при използването на Frosted :-)

Надявам се, че това е напълно достатъчно, но ако имате други въпроси, задайте ги в форумът. ;-)

 
bg/template.txt · Последна промяна: 2009/01/04 11:49 от alein
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki