Skip to content

Instantly share code, notes, and snippets.

@harikt
Created May 17, 2012 18:52
Show Gist options
  • Select an option

  • Save harikt/2720881 to your computer and use it in GitHub Desktop.

Select an option

Save harikt/2720881 to your computer and use it in GitHub Desktop.
Playing with Phly Mustache
{{!layout}}
{{%SUB-VIEWS}}
<html>
<body>
{{content}}
</body>
</html>
<?php
$package_dir = dirname( __DIR__ ) . '/auraphp/system/package';
$loader = require_once $package_dir . '/Aura.Autoload/scripts/instance.php';
$loader->add('Phly', dirname( __DIR__ ) .
'/aurasystem/include/phly_mustache/library'
);
$loader->register();
use Phly\Mustache\Mustache,
Phly\Mustache\Pragma\SubView,
Phly\Mustache\Pragma\SubViews;
$mustache = new Mustache();
$mustache->setTemplatePath( __DIR__ . '/template' );
// We need SubViews also and set the Mustache object to SubViews
$subViews = new SubViews($mustache);
// Or you can do via
// $subViews = new SubViews();
// $subViews->setManager($mustache);
$mustache->getRenderer()->addPragma($subViews);
$subView = new SubView('partials', array('name' => 'Matthew'));
// Only array works.
// $view = new \stdClass;
// $view->content = $subView;
$view = array('content' => $subView);
$rendered = $mustache->render('layout', $view);
echo $rendered;
{{!some-partial}}
Hello, {{name}}!
@weierophinney
Copy link
Copy Markdown

You need to tell Mustache about the pragma itself, too:

use Phly\Mustache\Pragma\SubViews; // note the plural
$subViews = new SubViews($mustache);

Once you have that, it should work.

@harikt
Copy link
Copy Markdown
Author

harikt commented May 18, 2012

Thank you for the tip, but when I am using $view as an object like below. It throws error . I feel there is something wrong . Not looked why, but array works looking through the tests I changed ;-) .

$view = new \stdClass;
$view->content = $subView;
$rendered = $mustache->render('layout', $view);
echo $rendered;

PHP Fatal error: Cannot use object of type stdClass as array in /media/Linux/aurasystem/include/phly_mustache/library/Phly/Mustache/Pragma/SubViews.php on line 143

Fatal error: Cannot use object of type stdClass as array in /media/Linux/aurasystem/include/phly_mustache/library/Phly/Mustache/Pragma/SubViews.php on line 143

May be you want to add a group , so we can get help even if we are in different timezone :-) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment