Last active
August 29, 2015 13:56
-
-
Save harikt/8841225 to your computer and use it in GitHub Desktop.
Aura.View standalone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> I should be in "main" something else </div> | |
<?php | |
// the view template | |
// set a new variable into the data | |
$this->title = 'Example Two-Step View'; | |
// show the same view output as before | |
echo '<p>Hello ' . $this->escapeHtml($this->name) . '. ' | |
. 'Your email address is ' . $this->escapeHtml($this->email) . '.</p>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title><?php echo $this->escapeHtml($this->title) ?></title> | |
</head> | |
<body> | |
<div class="main"><?php echo $this->content; ?></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* An example of integrating aura/view(two step view) and aura/html(html helpers) | |
* | |
* The escapeHtml is missing in the aura/html helper. | |
* | |
* You need to add | |
* | |
* 'escapeAttr' => function () { return new Helper\EscapeAttr; }, | |
* 'escapeHtml' => function () { return new Helper\EscapeHtml; }, | |
* | |
* in registry path/to/aura/html/scripts/helper_registry.php | |
* | |
*/ | |
$helper = require dirname(__DIR__) . '/vendor/aura/html/scripts/instance.php'; | |
require dirname(__DIR__) . '/vendor/autoload.php'; | |
use Aura\View\Finder; | |
use Aura\View\Helper; | |
use Aura\View\Manager; | |
use Aura\View\Template; | |
$view_manager = new Manager( | |
new Template, // template factory | |
$helper, // bare-bones helper object | |
new Finder, // view-template finder | |
new Finder // layout-template finder | |
); | |
// data for the templates | |
$data = [ | |
'name' => 'Hari KT', | |
'email' => 'hari@example.com', | |
]; | |
$view_manager->getViewFinder()->setName('inner', __DIR__ . '/template/inner.php'); | |
$view_manager->getLayoutFinder()->setName('outer', __DIR__ . '/template/outer.php'); | |
$view_template = 'inner'; | |
// the layout template | |
$layout_template = 'outer'; | |
// get the rendered output, then do what you like with it | |
$output = $view_manager->render($data, $view_template, $layout_template); | |
echo $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment