void $flexy->
compile (
string
$template
)
コンパイルする必要があれば、テンプレートのマークアップを PHP のコードに置換し、 compiledTemplate ディレクトリにファイル名を filename.{locale}.php として書き込みます。 テンプレートのコンパイルは必要に応じて以下の場合にのみ実行されます。
テンプレートエンジン自体に関する作業を行う場合を除き、 通常の利用では forceCompile フラグを有効にする必要はありません。
string $template
-
templateDir に設定された値と組み合わされ、
PHP コードにコンパイルされるべきテンプレートを指し示します。
string
- コンパイルされたファイルへのファイルパス (include でファイルを読み込むのに使えますが、
outputObject メソッドの利用を推奨します)
This function can not be called statically.
複数のファイルをコンパイルする
<?php
class controller_test
{
var $masterTemplate = "master.html"
var $template = "home.html"; // name of template
var $title; // page title;
var $numbers = array(); // an array example
/* start section - deals with posts, get variables etc.*/
function controller_test()
{
$this->start();
$this->output();
}
function start()
{
$this->title = "<Hello World>";
for ($i = 1;$i< 5;$i++) {
$this->numbers[$i] = "Number $i";
}
}
/* output section - probably best to put this in the default_controller class */
function output() {
$master = new HTML_Template_Flexy();
$master->compile('some_file_name');
$master->outputObject($this);
}
function outputBody() {
$body = new HTML_Template_Flexy();
$body->compile($this->template);
$body->outputObject($this);
}
}
new controller_test;
?>
マスターテンプレートの例
Page Header Goes here. {outputBody()} Page Footer Goes here
簡単な出力例
Page Header Goes here. some numbers Number 1 Number 2 Number 3 Number 4 Page Footer Goes here