本文整理汇总了PHP中tpl::data方法的典型用法代码示例。如果您正苦于以下问题:PHP tpl::data方法的具体用法?PHP tpl::data怎么用?PHP tpl::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tpl
的用法示例。
在下文中一共展示了tpl::data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders the template by page with the additional data
*
* @param Page|string $template
* @param array $data
* @param boolean $return
* @return string
*/
public function render($template, $data = [], $return = true)
{
if ($template instanceof Page) {
$page = $template;
$file = $page->templateFile();
$data = $this->data($page, $data);
} else {
$file = $template;
$data = $this->data(null, $data);
}
// check for an existing template
if (!file_exists($file)) {
throw new Exception('The template could not be found');
}
// merge and register the template data globally
tpl::$data = array_merge(tpl::$data, $data);
// load the template
return tpl::load($file, null, $return);
}
示例2: run
public function run($path = '/')
{
if ($this->kirby->option('patterns.lock') && !$this->kirby->site()->user()) {
go($this->kirby->option('error'));
}
// error handling
$whoops = new \Whoops\Run();
$whoops->pushHandler(function ($e) {
throw $e;
return \Whoops\Handler\Handler::QUIT;
});
$whoops->register();
tpl::$data = ['site' => $this->kirby->site(), 'pages' => $this->kirby->site()->children(), 'page' => $this->kirby->site()->find($this->kirby->option('home')), 'lab' => $this];
$router = new Router();
$router->register([['pattern' => '/', 'action' => function () {
$readme = $this->root() . DS . 'readme.md';
if (!is_dir($this->root())) {
$modal = $this->view('modals/folder');
} else {
$modal = null;
}
if (is_file($readme)) {
$markdown = kirbytext(f::read($readme));
} else {
$markdown = null;
}
return $this->view('layouts/main', ['title' => $this->title(), 'menu' => $this->menu(), 'content' => $this->view('views/dashboard', ['markdown' => $markdown]), 'modal' => $modal]);
}], ['pattern' => 'assets/(:any)', 'action' => function ($file) {
switch ($file) {
case 'index.js':
case 'index.min.js':
$mime = 'text/javascript';
break;
case 'index.css':
case 'index.min.css':
$mime = 'text/css';
break;
default:
return new Response('Not found', 'text/html', 404);
break;
}
// build the root for the file
$file = dirname(__DIR__) . DS . 'assets/dist/' . $file;
return new Response(f::read($file), $mime);
}], ['pattern' => '(:all)/preview', 'action' => function ($path) {
lab::$mode = 'preview';
$pattern = new Pattern($path);
$config = $pattern->config();
try {
$html = $pattern->render();
} catch (Exception $e) {
$html = '';
}
return $this->view('views/preview', ['pattern' => $pattern, 'html' => $html, 'background' => a::get($config, 'background', $this->kirby->option('patterns.preview.background')), 'css' => $this->kirby->option('patterns.preview.css', 'assets/css/index.css'), 'js' => $this->kirby->option('patterns.preview.js', 'assets/js/index.js')]);
}], ['pattern' => '(:all)', 'action' => function ($path) {
$pattern = new Pattern($path);
$file = null;
if (!$pattern->exists()) {
$filename = basename($path);
$path = dirname($path);
if ($path == '.') {
$preview = $this->view('previews/error', ['error' => 'The pattern could not be found']);
} else {
$pattern = new Pattern($path);
$file = $pattern->files()->get($filename);
if ($file) {
$preview = $this->preview($pattern, $file);
} else {
$preview = $this->view('previews/error', ['error' => 'The file could not be found']);
}
}
} else {
if ($file = $pattern->files()->get($pattern->name() . '.html.php')) {
go($pattern->url() . '/' . $file->filename());
} else {
if ($file = $pattern->files()->first()) {
go($pattern->url() . '/' . $file->filename());
} else {
$preview = $this->view('previews/empty');
}
}
}
if ($pattern->isHidden()) {
go($this->url());
}
return $this->view('layouts/main', ['title' => $this->title() . ' / ' . $pattern->title(), 'menu' => $this->menu(null, $path), 'content' => $this->view('views/pattern', ['preview' => $preview, 'info' => $this->view('snippets/info', ['pattern' => $pattern, 'file' => $file])])]);
}]]);
if ($route = $router->run($path ? $path : '/')) {
return new Response(call($route->action(), $route->arguments()));
} else {
go('error');
}
}
示例3: template
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array())
{
// apply the basic template vars
tpl::$data = array_merge(tpl::$data, array('kirby' => $this, 'site' => $this->site(), 'pages' => $this->site()->children(), 'page' => $page), $page->templateData(), $data, $this->controller($page, $data));
return tpl::load($page->templateFile());
}
示例4: template
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array())
{
// apply the basic template vars
tpl::$data = array_merge(tpl::$data, array('kirby' => $this, 'site' => $this->site(), 'pages' => $this->site()->children(), 'page' => $page), $page->templateData(), $data, $this->controller($page, $data));
if (!file_exists($page->templateFile())) {
throw new Exception('The default template could not be found');
}
return tpl::load($page->templateFile());
}
示例5: template
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array())
{
// set the timezone for all date functions
date_default_timezone_set($this->options['timezone']);
// load all language variables
$this->localize();
// load all extensions
$this->extensions();
// load all plugins
$this->plugins();
// apply the basic template vars
tpl::$data = array_merge(array('kirby' => $this, 'site' => $this->site(), 'pages' => $this->site()->children(), 'page' => $page), $data, $this->controller($page, $data));
return tpl::load($page->templateFile());
}
示例6: template
/**
* Template configuration
*/
protected static function template(Page $page, $data = array())
{
// apply the basic template vars
tpl::$data = array_merge(array('site' => static::$site, 'pages' => static::$site->children(), 'page' => $page), $data, static::controller($page, $data));
return tpl::load($page->templateFile());
}