Created
May 17, 2012 18:52
-
-
Save harikt/2720881 to your computer and use it in GitHub Desktop.
Playing with Phly Mustache
This file contains hidden or 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
| {{!layout}} | |
| {{%SUB-VIEWS}} | |
| <html> | |
| <body> | |
| {{content}} | |
| </body> | |
| </html> |
This file contains hidden or 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 | |
| $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; |
This file contains hidden or 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
| {{!some-partial}} | |
| Hello, {{name}}! |
Author
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
You need to tell Mustache about the pragma itself, too:
Once you have that, it should work.