Created
September 8, 2017 10:11
-
-
Save ilyar/3c34184d7290d7fa3f20d335e4584c4c to your computer and use it in GitHub Desktop.
Sample BEM Server Rendering on PHP-stack
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 | |
# file: public/index.php | |
# | |
# Sample BEM Server Rendering on PHP-stack | |
# | |
# composer require nacmartin/phpexecjs | |
# | |
define('ROOT_DIR', dirname(__DIR__)); | |
require ROOT_DIR . 'vendor/autoload.php'; | |
use Nacmartin\PhpExecJs\PhpExecJs; | |
$node = new PhpExecJs(); | |
$node->createContextFromFile(realpath(ROOT_DIR . '/desktop.bundles/index/index.bemhtml+bemtree.js')); | |
$data = [ | |
'block' => 'page', | |
'content' => 'ok', | |
]; | |
$json = json_encode($data, JSON_FORCE_OBJECT); | |
// Used NodeJs or php-v8js | |
$result = $node->evalJs('BEMHTML.apply(BEMTREE.apply(' . $json . '))'); | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment