PHP code example of nixn / hiccup
1. Go to this page and download the library: Download nixn/hiccup 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/ */
nixn / hiccup example snippets
['form #the-form .form.pretty [method]post [action]/my-script.php', ['title' => 'Please fill out!'],
['label', /*...*/],
['input', /*...*/],
]
class Log extends Template_Base
{
public function hiccup(): mixed
{
return Hiccup::each(
(new OutputLine('debug message'))->set_parent($this, 'debug_'),
(new OutputLine('usual message'))->set_parent($this, 'usual_'),
(new OutputLine('error message'))->set_parent($this, 'error_'),
);
}
protected function debug_p_class(): string
{
return 'gray';
}
protected function error_p_class(): string
{
return 'red';
}
}
class OutputLine extends Template_Base
{
public function __construct(private string $message) {}
public function hiccup(): mixed
{
return ['p', ['class' => $this->p_class()], $this->message];
}
}
class IndexPage extends HTML5
{
protected function title(): string
{
return 'Hello, world!';
}
protected function body(): mixed
{
return ['h1', 'Welcome, everyone! ', ['small', ':-)']];
}
}
echo Hiccup::html(new IndexPage());
class Page extends HTML5
{
public function __construct(
private bool $k [rel]stylesheet [crossorigin]anonymous', [
'href' => "https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css",
'integrity' => "sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH",
]];
}
protected function body(): mixed
{
return Hiccup::each(
$this->content(),
$this->to5eqruptLy",
]],
$this->body_end(),
);
}
}
class IndexPage extends Page
{
public function __construct()
{
parent::__construct(false);
}
protected function content(): mixed
{
return ['h1.bg-secondary', 'Hello, world!'];
}
}
echo Hiccup::html(new IndexPage());