本文整理汇总了PHP中League\Plates\Engine::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Engine::render方法的具体用法?PHP Engine::render怎么用?PHP Engine::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Plates\Engine
的用法示例。
在下文中一共展示了Engine::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Handler.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
$page = $request->getAttribute('page', '/index');
$content = $this->contentLoader->getContent($page);
$template = $content->getMetadataEntry('template');
$params = array_merge($content->getMetadata(), ['html' => $content->getHtml()]);
$response->getBody()->write($this->plates->render($template, $params));
return $response->withHeader('Content-Type', 'text/html');
}
示例2: __invoke
/**
* @param $template
* @return bool
*/
public function __invoke($template)
{
//
$template = $this->getPlatesPath($template);
// get the HTML for whatever is going on
echo $this->engine->render($template);
// because we echo'd already, we return false so it's not double-echo'd by wordpress'
// default `include $template` statement
return false;
}
示例3: index
/**
* @param BatchManager $batches
* @param ServerRequestInterface $request
* @param string $task
*
* @return View
*/
public function index(BatchManager $batches, ServerRequestInterface $request, $task = 'custom')
{
// Interactive mode
$query = $request->getQueryParams();
if (array_key_exists('interactive', $query)) {
$this->configuration['tasks'] = $query['interactive'];
}
$task = $this->getTask($task);
$sync = array_get($query, 'sync');
$method = $sync ? 'runTask' : 'getCommandsFrom';
$commands = $this->runner->{$method}($task);
// Store commands for retrieval
$hash = $batches->set($commands);
return $this->views->render('index', ['tasks' => $commands, 'hash' => $hash, 'url' => $this->configuration->get('url')]);
}
示例4: __invoke
public function __invoke(array $input)
{
$name = 'index';
if (!empty($input['name'])) {
$name = $input['name'];
}
// $filename = APPPATH . 'templates/static/' . $name;
// if (file_exists($filename)) {
// echo "The file $filename does not exist";
// die('the file does not exist');
// }
// Create new Plates instance
$plates = new Engine(APPPATH . 'templates');
// Register extension
$plates->loadExtension(new Utils());
// Check static page or partial exists
if ($plates->exists('static/' . $name)) {
// Render a template
$template = $plates->render('static/' . $name);
} else {
header("HTTP/1.0 404 Not Found");
echo "PHP continues.\n";
echo "Not after a die, however.\n";
die;
}
// return
return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]);
}
示例5: render
/**
* Render the template.
*
* @param string $name
* @param string[] $data
*
* @throws \LogicException
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function render($name, array $data = [])
{
if (!isset($this->response)) {
throw new \LogicException(sprintf('Invalid %s object instance', ResponseInterface::class));
}
return $this->response->write($this->plates->render($name, $data));
}
示例6: render
/**
* Render a string
*
* @param string $template The template content to render
* @param array $locals The variable to use in template
* @return null|string
*/
public function render($template, array $locals = array())
{
$tmpName = uniqid('plates_tmp_', false);
$tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tmpName;
if (!is_null($this->plates->getFileExtension())) {
$tmpPath .= '.' . $this->plates->getFileExtension();
}
$isTmpRegister = $this->plates->getFolders()->exists(sys_get_temp_dir());
if (!$isTmpRegister) {
$this->plates->addFolder(sys_get_temp_dir(), sys_get_temp_dir());
}
file_put_contents($tmpPath, $template);
$data = $this->plates->render(sys_get_temp_dir() . '::' . $tmpName, $locals);
unlink($tmpPath);
if (!$isTmpRegister) {
$this->plates->getFolders()->remove(sys_get_temp_dir());
}
return $data;
}
示例7: render
public function render($name, $data = [], $echo = false)
{
$data["layoutName"] = $this->getLayoutName();
$data["crud"] = $this;
$html = $this->template->render($name, $data);
if ($echo) {
echo $html;
}
return $html;
}
示例8: render
protected function render($name)
{
if (!count($this->templateVars)) {
return $this->templater->render($name);
}
$vars = [];
foreach ($this->templateVars as $var) {
$vars = array_merge($vars, $var);
}
return $this->templater->render($name, $vars);
}
示例9: render
/**
* @param string $type
* @return string
*/
public function render($type = null)
{
$templates = new Engine($this->viewPath);
if ($type === null) {
if ($this->media === false) {
$type = 'media';
} else {
$type = 'thumbnail';
}
}
return $templates->render($type, $this->toArray());
}
示例10: __invoke
public function __invoke(array $input)
{
$name = 'world';
if (!empty($input['name'])) {
$name = $input['name'];
}
////////////////////
$application = new Application();
$application_data = $application->is_pjax();
//print_r( '<pre>' );
// print_r( $application_data );
//print_r( '</pre>');
////////////////////
// simple
// Create new Plates instance
// $plates = new Engine(APPPATH.'templates');
// Render a template
// $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]);
// $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]);
$data = ['friends' => ['mikka', 'makka', 'zorro']];
// $friends = [
// ['name', 'zorro'],
// ];
////////////////////
// using folders
// Create new Plates instance
$plates = new Engine(APPPATH . 'templates');
// Register a Plates extension
$plates->loadExtension(new Utils());
// Add folders
$plates->addFolder('layout', APPPATH . 'templates');
$plates->addFolder('partials', APPPATH . 'templates/partials');
$plates->addFolder('static', APPPATH . 'templates/static');
// assign data to plates
$plates->addData($data, 'layout');
// Render
$template = $plates->render('partials::profile', ['name' => $name]);
////////////////////
$invitation = 'I invite you';
// return
return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]);
}
示例11: testRender
public function testRender()
{
$this->assertSame($this->engine->render('simple'), $this->strategy->render('simple'));
}
示例12: insert
/**
* Output a rendered template.
* @param string $name
* @param array $data
* @return null
*/
protected function insert($name, array $data = array())
{
echo $this->engine->render($name, $data);
}
示例13: render
/**
* @param PayloadInterface $payload
*
* @return string
*/
private function render(PayloadInterface $payload)
{
$template = $payload->getSetting('template');
$output = $payload->getOutput();
return $this->engine->render($template, $output);
}
示例14: render
/**
* Render a plate template and return with a PSR-7 Response object.
*
* @param ResponseInterface $response
* @param $template
* @param array $data
*
* @return ResponseInterface
*/
public function render(ResponseInterface $response, $template, array $data = [])
{
$response->getBody()->write($this->engine->render($template, $data));
return $response;
}
示例15: evaluate
/**
* Evaluates the template with its variables.
*
* @param string $template The template relative path
* @param array $vars The template variables
*
* @return string
*/
public function evaluate($template, array $vars = [])
{
$reference = $this->loadTemplate($template, $vars);
return $this->plates->render($template, $reference->getVariables());
}