Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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