Skip to content

Instantly share code, notes, and snippets.

@ilyar
Created September 8, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyar/3c34184d7290d7fa3f20d335e4584c4c to your computer and use it in GitHub Desktop.
Save ilyar/3c34184d7290d7fa3f20d335e4584c4c to your computer and use it in GitHub Desktop.
Sample BEM Server Rendering on PHP-stack
<?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