Skip to content

Instantly share code, notes, and snippets.

@andikasputra
Created August 6, 2021 12:48
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 andikasputra/963bdab1fb1a2c51049f1ebd72f0e3ca to your computer and use it in GitHub Desktop.
Save andikasputra/963bdab1fb1a2c51049f1ebd72f0e3ca to your computer and use it in GitHub Desktop.
php server side rendering
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Spatie\Ssr\Renderer;
use Spatie\Ssr\Engines\Node;
$features = [
['id' => 1, 'name' => 'NVMe SSD Super Cepat', 'description' => '100% Enterprise NVMe SSD untuk performa website secepat kilat'],
['id' => 2, 'name' => 'Cloud Backup', 'description' => 'Backup harian ke Cloud menjamin keamanan data penting anda']
];
$engine = new Node("/home/andika/.nvm/versions/node/v14.17.1/bin/node", __DIR__.'/../dist');
$renderer = new Renderer($engine);
$res = $renderer
->context('user', ['name' => 'Andika'])
->context('features', $features)
->entry(__DIR__.'/../dist/app-server.js')
->render();
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="app">
<?= $res ?>
</div>
<script defer src="../dist/app-client.js"></script>
<script>
window.user = <?= json_encode(['name' => 'Andika']) ?>;
window.features = <?= json_encode($features) ?>;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment