Created
August 6, 2021 12:48
-
-
Save andikasputra/963bdab1fb1a2c51049f1ebd72f0e3ca to your computer and use it in GitHub Desktop.
php server side rendering
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 | |
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