$flexy->compile()

$flexy->compile() -- コンパイルする必要があればマークアップを PHP にコンパイルする

概要

void $flexy-> compile (string $template)

説明

コンパイルする必要があれば、テンプレートのマークアップを PHP のコードに置換し、 compiledTemplate ディレクトリにファイル名を filename.{locale}.php として書き込みます。 テンプレートのコンパイルは必要に応じて以下の場合にのみ実行されます。

テンプレートエンジン自体に関する作業を行う場合を除き、 通常の利用では forceCompile フラグを有効にする必要はありません。

パラメータ

返り値

string - コンパイルされたファイルへのファイルパス (include でファイルを読み込むのに使えますが、 outputObject メソッドの利用を推奨します)

注意

この関数は、スタティックにコールする ことはできません。

例 40-1複数のファイルをコンパイルする


<?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($this->masterTemplate);
$master->outputObject($this);
}

function outputBody() {
$body = new HTML_Template_Flexy();
$body->compile($this->template);
$body->outputObject($this);
}



}

new controller_test;
?>

例 40-2マスターテンプレートの例

Page Header Goes here. 

{outputBody()}

Page Footer Goes here

例 40-3簡単な出力例

Page Header Goes here. 

some numbers
Number 1
Number 2
Number 3
Number 4

Page Footer Goes here