Application::displayPage
標準のテンプレート変数を使ってページを表示し、レスポンスを終えます
説明
public void Application::displayPage( string $template )
Application::fetchPageでテンプレートを処理し(そのため$page、$site、$inなどが使えます)、ページを出力してレスポンスを終えます(レスポンスの終了を参照)。displayPage()の後のコードは実行されません。
ページを表示するときは、いつもこのメソッドを使います。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $template | string | テンプレートのルートからの相対パスで書いたテンプレート名。.tplは付けません(news/detail) |
例
htdocs/_fegg/site/src/Controller/News.php
<?php
namespace Site\Controller;
defined('FEGG_CORE_DIR') || exit;
class News extends Controller
{
public function detail($id = '')
{
$this->page['title'] = 'Hello';
$this->displayPage('news/detail');
}
}
htdocs/_fegg/site/template/main/tpl/news/detail.tpl
<h1>{{ $page.title }}</h1>
Output
<h1>Hello</h1>
エラー
テンプレートが見つからないときはFegg\Template\TemplateExceptionを投げます(Lintとエラーを参照)。