1. Go to this page and download the library: Download icetea/icecube library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
icetea / icecube example snippets
namespace App\Components;
use IceTea\IceCube\SingleFileComponent;
use IceTea\IceDOM\HtmlNode;
class Counter extends SingleFileComponent
{
public function __construct(
public int $initialCount = 0,
public string $label = 'Counter',
) {}
public function render(): HtmlNode
{
return _div(['class' => 'counter-container'], [
_h2($this->label),
_p([
_span('Count: '),
_strong(['class' => 'count-value'], [
_span($this->initialCount)->data_ref('counter'),
]),
]),
_div([
_button(['class' => 'btn'], '-')->data_ref('decrementBtn'),
_button(['class' => 'btn'], '+')->data_ref('incrementBtn'),
], ['class' => 'button-group']),
]);
}
}
use IceTea\IceCube\Compiler\IceCubeCompiler;
use IceTea\IceCube\Compiler\EmbedStyleScriptCompiler;
$compiler = new IceCubeCompiler(
prefixClass: 'App\\Components',
sourceDir: __DIR__ . '/../app/Components',
compiledPhpDir: storage_path('icecube'),
compiledAssetsDir: public_path('icecube'),
publicUrl: '/icecube',
scriptCompiler: new EmbedStyleScriptCompiler()
);
// For development: compile on-demand via autoloader (automatic)
// For production: pre-compile all components
$compiler->scanAndCompile();
// During build/deployment
use IceTea\IceCube\IceCubeRegistry;
$compiler->scanAndCompile();
IceCubeRegistry::storeCache(storage_path('icecube/cache.php'));
// In production bootstrap
IceCubeRegistry::loadCache(storage_path('icecube/cache.php'));
use IceTea\IceCube\Compiler\IceCubeCompiler;
use IceTea\IceCube\Compiler\ViteScriptCompiler;
use IceTea\IceCube\Compiler\ScssStyleCompiler;
// Optional: Configure SCSS with custom import paths
$styleCompiler = new ScssStyleCompiler();
$scss = $styleCompiler->getCompiler();
$scss->addImportPath(base_path('app/Components'));
$compiler = new IceCubeCompiler(
prefixClass: 'App\\Components',
sourceDir: base_path('app/Components'),
compiledPhpDir: storage_path('app/private/icecube'),
compiledAssetsDir: storage_path('app/public/icecube'),
publicUrl: '/storage/icecube',
scriptCompiler: new ViteScriptCompiler(),
styleCompiler: $styleCompiler, // Optional: for SCSS support
);
$compiler->scanAndCompile();
// When using Vite, skip storing styles in cache (they're handled by Vite)
IceCubeRegistry::storeCache(
storage_path('app/private/icecube/cache.php'),
class MyComponent extends SingleFileComponent
{
public function __construct(
public string $title, // Passed to client
public array $items, // Passed to client
private string $secret, // NOT passed to client
) {}
}
_button('Click me')->data_ref('myButton')
<style>
/* Scoped: only affects this component */
.button { color: blue; }
</style>
<style global>
/* Global: affects entire page */
body { margin: 0; }
</style>
use IceTea\IceCube\Compiler\ScssStyleCompiler;
$compiler = new IceCubeCompiler(
// ... other params
styleCompiler: new ScssStyleCompiler()
);