https://github.com/baylorrae/htmlgen
A lightweight DSL for HTML generation in PHP 5.3
https://github.com/baylorrae/htmlgen
Last synced: 9 months ago
JSON representation
A lightweight DSL for HTML generation in PHP 5.3
- Host: GitHub
- URL: https://github.com/baylorrae/htmlgen
- Owner: BaylorRae
- Created: 2011-04-04T22:17:12.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-05-03T18:35:26.000Z (about 15 years ago)
- Last Synced: 2025-04-03T02:51:14.452Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 438 KB
- Stars: 2
- Watchers: 1
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# htmlgen
A lightweight DSL for HTML generation in PHP
## Requirements
PHP >= 5.3
## Code example
```php
"bar",
"hello" => "world",
"123" => "456",
"abc" => "xyz"
);
h::set_indent_pattern(" ");
h::html(function(){
h::head(function(){
h::meta(array("http-equiv"=>"Content-Type", "content"=>"text/html; charset=UTF-8"));
h::link(array("rel"=>"stylesheet", "type"=>"text/css", "href"=>"global.css"));
});
h::body(function(){
h::div(array("id"=>"wrapper"), function(){
h::h1("Hello, World", array("class"=>"title"));
h::comment("navigation");
h::ul(array("class"=>"links"), function(){
foreach(array(1,2,3) as $x)
h::li(function() use($x){
h::a("Link {$x}", "#{$x}");
});
});
h::comment("let's see some text");
h::p("Lorem ipsum dolor sit amet, consectetur adipisicing elit...");
h::comment("now for a table");
h::table(function(){
# sadly, i'm not sure how to get around this at the moment :( help me make this awesome
global $table_data;
h::tr(array("class"=>"header"), function(){
h::th("key");
h::th("value");
});
foreach($table_data as $k => $v){
h::tr(array("class"=>h::cycle(array("odd", "even"))), function() use($k,$v){
h::td($k);
h::td($v);
});
}
});
});
});
});
?>
```
## Output
Hello, World
Lorem ipsum dolor sit amet, consectetur adipisicing elit...
key
value
foo
bar
hello
world
456
abc
xyz
## Try it and see!
$ cd htmlgen
$ php example.php